예제 #1
0
 public function printAll(Mockster $mockster)
 {
     $class = (new \ReflectionClass($mockster->mock()))->getParentClass();
     $all = [];
     foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
         $arguments = array_map(function () {
             return Argument::any();
         }, $method->getParameters());
         $calls = $mockster->__call($method->getName(), $arguments)->has()->calls();
         if ($calls) {
             $all[] = $this->printCalls($method->getName(), $calls);
         }
     }
     return "History of [{$class->getName()}]\n  " . implode("\n  ", $all);
 }
예제 #2
0
 function testCanGetMoreGeneral()
 {
     Mockster::stub($this->foo->bar('one'))->will()->return_('bar');
     Mockster::stub($this->foo->bar(Argument::any()))->will()->return_('foo');
     $this->assert($this->mock->bar('one'), 'bar');
     $this->assert($this->mock->bar('two'), 'foo');
 }
예제 #3
0
 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')");
 }