Piszę test do testowania obserwatora, jednak coś mi nie chce działać.
<?php namespace Ultilate\GameBundle\QueueSystem; use Ultilate\GameBundle\Listener; abstract class Action implements Listener { protected $model_name; public function __construct() { $this->loadPhases(); } public function notify( $time ) { /*foreach ( $this->phases as $phase ) { $phase->notify( $time ); }*/ { $this->phases[$i]->notify( $time ); } } protected function loadPhases() { } }
<?php namespace Ultilate\GameBundle\QueueSystem; use Ultilate\GameBundle\Listener; abstract class Phase implements Listener { public function notify( $time ) { $this->scenario(); } public function scenario() { } }
<?php namespace Ultilate\GameBundle\Tests\QueueSystem; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class ActionTest extends WebTestCase { public function testNotyfingActions() { $action = $this->getMockForAbstractClass( "Ultilate\GameBundle\QueueSystem\Action" ); for ( $i = 0; $i < 4; $i++ ) { $phases[$i] = $this->getMockForAbstractClass( "Ultilate\GameBundle\QueueSystem\Phase" ); $phases[$i]->expects( $this->once() ) ->method( "notify" ) ->with( $this->equalTo( $time ) ); } $reflector = new \ReflectionProperty( 'Ultilate\GameBundle\QueueSystem\Action', 'phases' ); $reflector->setAccessible( true ); $reflector->setValue( $action, $phases ); $action->notify( $time ); }
Pierwszy kod to testowana klasa, drugi to zależny obiekt, a trzecia to test jednostkowy.
Po odpaleniu testu wyskakuje błąd:
Kod
There was 1 failure:
1) Ultilate\GameBundle\Tests\QueueSystem\ActionTest::testNotyfingActions
Expectation failed for method name is equal to <string:notify> when invoked 1 time(s).
Method was expected to be called 1 times, actually called 0 times.
1) Ultilate\GameBundle\Tests\QueueSystem\ActionTest::testNotyfingActions
Expectation failed for method name is equal to <string:notify> when invoked 1 time(s).
Method was expected to be called 1 times, actually called 0 times.