0

モックアップ ビルダーで奇妙な動作を見つけました。なぜこれが起こるのか説明してもらえますか?

ここに私のテストコードがあります:

class PlaceTest extends \PHPUnit_Framework_TestCase
{
    const API_KEY = 'test-api';

    public function testConstruct()
    {
        $google = $this->getMockBuilder('GusDeCooL\GooglePhp\Google')
            ->setConstructorArgs(array(self::API_KEY))
                            ->setMethods(array('getKey'))
            ->getMock();
        $google->expects($this->any())
            ->method('getKey')
            ->will($this->returnValue(self::API_KEY));

        /* @var $google \GusDeCooL\GooglePhp\Google */
        $place = new Place($google);
        $this->assertInstanceOf('GusDeCooL\GooglePhp\Component\Place\Place', $place);
        $this->assertInstanceOf('GusDeCooL\GooglePhp\Google', $place->getParent());
        $this->assertEquals(self::API_KEY, $place->getKey());
        return $place;
    }



    /**
     * @param Place $place
     *
     * @depends testConstruct
     */
    public function testGetKey(Place $place)
    {
        $this->assertInstanceOf('GusDeCooL\GooglePhp\Google', $place->getParent());
        $this->assertEquals(self::API_KEY, $place->getKey());
    }
}

そして、これが実際のクラスのコードです

<?php



namespace GusDeCooL\GooglePhp\Component\Place;

use GusDeCooL\GooglePhp\Component\ChildInterface;
use GusDeCooL\GooglePhp\Google;
use GusDeCooL\GooglePhp\Place\Nearby;

class Place implements ChildInterface
{
    /**
     * @var Google
     */
    private $parent;

    /**
     * @var Nearby
     */
    private $nearby;

    public function __construct(Google $parent)
    {
        $this->setParent($parent);
    }


    /**
     * API Key
     * @return string
     */
    public function getKey()
    {
        return $this->getParent()->getKey();
    }
}

テストの実行中、実行中はテストPlaceTest::testConstruct()$place->getKey()合格しますが、エラーになりますPlaceTest::testGetKey()

それはどうしてですか?

4

1 に答える 1