function testPrintStubHistory() { Mockster::stub($this->foo->foo(Arg::any(), Arg::any()))->will()->return_('foo')->once()->then()->return_(['foo'])->once()->then()->return_(new \DateTime('2011-12-13 14:15:16 UTC'))->once()->then()->throw_(new \InvalidArgumentException("Oh no")); $this->mock->foo(4, 2); $this->mock->foo('One', 'Two'); $this->mock->foo('Three'); try { $this->mock->foo('Four', new RecordStubUsageTest_ToString()); } catch (\InvalidArgumentException $ignored) { } $this->assert((new HistoryPrinter())->printStub($this->foo->foo()), "No calls recorded for [" . RecordStubUsageTest_FooClass::class . "::foo()]"); $this->assert((new HistoryPrinter())->printStub($this->foo->foo(Arg::integer(), Arg::integer())), "History of [" . RecordStubUsageTest_FooClass::class . "::foo()]\n" . " foo(4, 2) -> 'foo'"); $this->assert((new HistoryPrinter())->printStub($this->foo->foo(Arg::string(), Arg::any())), "History of [" . RecordStubUsageTest_FooClass::class . "::foo()]\n" . " foo('One', 'Two') -> ['foo']\n" . " foo('Three', NULL) -> <DateTime>(2011-12-13T14:15:16+00:00)\n" . " foo('Four', <" . RecordStubUsageTest_ToString::class . ">('foo')) !! <InvalidArgumentException>('Oh no')"); }
function testPropertyStubbingOverwritesArgumentsStubbing() { /** @var Mockster|InjectMocksTest_InjectableClass $injectable */ $injectable = new Mockster(InjectMocksTest_InjectableClass::class); /** @var Mockster|InjectMocksTest_FooClass $injected */ $injected = new Mockster(InjectMocksTest_FooClass::class); Mockster::stub($injected->foo())->will()->return_('argument'); Mockster::stub($injectable->bas->foo())->will()->return_('property'); /** @var InjectMocksTest_InjectableClass $mock */ $mock = $injectable->__uut(['bas' => $injected->__mock()]); $this->assert($mock->bas->foo(), 'property'); }
function testUnitUnderTest() { $this->mock = $this->foo->__uut(); $this->assert($this->mock->constructorCalled); $this->assert->not(Mockster::stub($this->foo->foo())->isStubbed()); }