Пример #1
0
 /**
  * A test ended.
  *
  * @param PHPUnit_Framework_Test $test
  * @param float $time
  *
  * @throws \Exception
  */
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     try {
         foreach ($this->_mocks as $mock) {
             if ($mock->__phpunit_hasMatchers() && $test instanceof \PHPUnit_Framework_TestCase) {
                 $test->addToAssertionCount(1);
             }
             $mock->__phpunit_verify();
         }
     } catch (\Exception $e) {
         BaseMock::__classMock_unregisterListener();
         $this->_mocks = [];
         throw $e;
     }
     BaseMock::__classMock_unregisterListener();
     $this->_mocks = [];
 }
Пример #2
0
 /**
  * Set up class mocker
  *
  * @return void
  */
 public function setUp()
 {
     BaseMock::setDefaultCallBehavior(BaseMock::DEFAULT_BEHAVIOUR_RETURN_NULL);
     $this->classMocker = new ClassMocker();
     //$this->classMocker->setGenerationDir('./var/generation');
     $this->classMocker->mock('Foobar\\*');
     $this->classMocker->registerTrait(TraitA::class);
     $this->classMocker->registerTrait(TraitB::class);
     $this->classMocker->registerTrait(TraitC::class);
     $this->classMocker->registerTrait(DummyTrait::class, 'Foobar\\*', 1000);
     // test footprints
     $footprintA = new ClassFootprint();
     $footprintA->addInterface(Readable::class);
     $footprintA->addInterface(Talkable::class);
     $footprintB = new ClassFootprint();
     $footprintB->setParent('Foobar\\BaseClass');
     $this->classMocker->registerFootprint('Foobar\\BaseClass', $footprintA);
     $this->classMocker->registerFootprint('Foobar\\TestClass', $footprintB);
     $this->classMocker->enable();
 }
Пример #3
0
 /**
  * Set up
  *
  * @return void
  */
 public function setUp()
 {
     BaseMock::setDefaultCallBehavior(BaseMock::DEFAULT_BEHAVIOUR_RETURN_NULL);
 }
Пример #4
0
 /**
  * Test different default behaviors
  *
  * @return void
  * @test
  */
 public function testDefaultMethodCallBehavior()
 {
     $dummy = new DummyClass();
     $dummy->foobar = 10;
     // return null for none defined methods
     BaseMock::setDefaultCallBehavior(BaseMock::DEFAULT_BEHAVIOUR_RETURN_NULL);
     $this->assertNull($dummy->someMethod(10));
     $this->assertSame('', $dummy->__toString());
     // return self for none defined methods
     BaseMock::setDefaultCallBehavior(BaseMock::DEFAULT_BEHAVIOUR_RETURN_SELF);
     $this->assertSame($dummy, $dummy->someMethod(10));
     $this->assertSame('', $dummy->__toString());
     // call handle for none defined methods
     BaseMock::setDefaultCallBehavior(function ($a) {
         return $this->foobar + $a;
     });
     $this->assertEquals(20, $dummy->someMethod(10));
     // throw exception for none defined methods
     BaseMock::setDefaultCallBehavior(BaseMock::DEFAULT_BEHAVIOUR_THROW_EXCEPTION);
     try {
         $dummy->someMethod(10);
         $this->fail("Should throw error on invalid method call");
     } catch (\BadMethodCallException $e) {
         $this->assertEquals('Method JSiefer\\ClassMocker\\TestClasses\\DummyClass::someMethod() does not exist', $e->getMessage());
     }
     try {
         BaseMock::setDefaultCallBehavior('Something Invalid');
         $this->fail("Should throw error on invalid behavior option");
     } catch (\InvalidArgumentException $e) {
         $this->assertEquals('Invalid behavior option (Something Invalid)', $e->getMessage());
     }
     BaseMock::setDefaultCallBehavior(BaseMock::DEFAULT_BEHAVIOUR_RETURN_NULL);
 }