/** * Make sure the test listener will validate any * object created during a test at the end of the test * * @return void * @test */ public function testListener() { $classMocker = new ClassMocker(); $classMocker->mock('TestListenerTest_SomeClass'); $classMocker->autoload('TestListenerTest_SomeClass'); $testCase = $this->getMockForAbstractClass(\PHPUnit_Framework_TestCase::class); $listener = new TestListener(); $listener->startTest($testCase); $testObject = new \TestListenerTest_SomeClass(); $testObject->expects($this->once())->method('test'); try { $listener->endTest($testCase, 0); $this->fail("Should fail"); } catch (\PHPUnit_Framework_ExpectationFailedException $e) { $this->assertStringStartsWith('Expectation failed for method name is equal to', $e->getMessage()); } // everything has been reset so no error should be thrown $listener->endTest($testCase, 0); }
/** * Trait should not allow any magic methods * * Magic methods like __call() can not be used by traits * without causing conflict with the BaseMock * * Instead use ___call() methods * * @return void * @test * @expectedException \RuntimeException * @expectedExceptionMessage Trait magic method ClassUsingInvalidTrait::__call() */ public function shouldFailOnInvalidTraitMethod() { $fwMocker = new ClassMocker(); $fwMocker->registerTrait(InvalidTrait::class, 'ClassUsingInvalidTrait'); $fwMocker->mock('ClassUsingInvalidTrait'); $fwMocker->autoload('ClassUsingInvalidTrait'); }