/**
  * @return void
  */
 public function test_function()
 {
     // prepare
     $this->setExpectedException('\\UnexpectedValueException', 'Invalid method');
     MockMethodCalls::init(['collection' => []]);
     // invoke logic & test
     MockMethodCalls::getInstance()->recordArguments(new \stdClass(), 'fooBar', []);
 }
 /**
  * @return void
  */
 public function test_function()
 {
     // prepare
     $this->setExpectedException('\\UnexpectedValueException', 'Invalid method');
     MockMethodCalls::init(['collection' => []]);
     $reflection = new \ReflectionClass(MockMethodCalls::getInstance());
     $validateCollectionsMethod = $reflection->getMethod('getFullTraceDetails');
     $validateCollectionsMethod->setAccessible(true);
     // invoke logic & test
     $validateCollectionsMethod->invoke(MockMethodCalls::getInstance(), new \stdClass(), 'fooBar');
 }
 /**
  * @return void
  */
 public function test_function()
 {
     // invoke logic
     MockMethodCalls::init([]);
     // prepare
     $reflection = new \ReflectionClass('\\DbMockLibrary\\MockMethodCalls');
     $callArgumentsProperty = $reflection->getProperty('callArguments');
     $callArgumentsProperty->setAccessible(true);
     // test
     MockMethodCalls::getInstance()->recordArguments(new \Exception(), 'getMessage', ['bar']);
     // test
     $this->assertEquals([['Exception::getMessage' => ['bar']]], $callArgumentsProperty->getValue(MockMethodCalls::getInstance()));
 }
 /**
  * @return void
  */
 public function test_function()
 {
     // prepare
     MockMethodCalls::init([]);
     $reflection = new \ReflectionClass('\\DbMockLibrary\\MockMethodCalls');
     $traceProperty = $reflection->getProperty('traces');
     $traceProperty->setAccessible(true);
     // test
     MockMethodCalls::getInstance()->recordTrace();
     // prepare
     $trace = $traceProperty->getValue(MockMethodCalls::getInstance());
     // test
     $this->assertArraySubset(['function' => 'test_function', 'class' => 'Test\\MockMethodCalls\\RecordTraceTest'], $trace[0][0]);
 }
 /**
  * @dataProvider getData
  *
  * @param array $data
  *
  * @return void
  */
 public function test_function(array $data)
 {
     // prepare
     MockMethodCalls::init([]);
     $traces = [[['function' => 'getMessage', 'class' => 'Exception', 'args' => ['fooBar'], 'foo' => 'bar']]];
     $reflection = new \ReflectionClass('\\DbMockLibrary\\MockMethodCalls');
     $traceProperty = $reflection->getProperty('traces');
     $traceProperty->setAccessible(true);
     $traceProperty->setValue(MockMethodCalls::getInstance(), $traces);
     $getFullTraceDetailsMethod = $reflection->getMethod('getFullTraceDetails');
     $getFullTraceDetailsMethod->setAccessible(true);
     // invoke logic
     $result = $getFullTraceDetailsMethod->invoke(MockMethodCalls::getInstance(), $data['class'], $data['method']);
     // test
     $this->assertEquals($data['expected'], $result);
 }
 /**
  * @dataProvider getData
  *
  * @param array $data
  *
  * @return void
  */
 public function test_function(array $data)
 {
     // prepare
     MockMethodCalls::init([]);
     $traces = [[['function' => 'getMessage', 'class' => 'Exception', 'args' => ['foo']]], [['function' => 'getMessage', 'class' => 'Exception', 'args' => ['foo']]]];
     $reflection = new \ReflectionClass('\\DbMockLibrary\\MockMethodCalls');
     $traceProperty = $reflection->getProperty('traces');
     $traceProperty->setAccessible(true);
     $traceProperty->setValue(MockMethodCalls::getInstance(), $traces);
     // invoke logic
     if (isset($data['arguments'])) {
         $result = MockMethodCalls::getInstance()->wasCalledCount($data['class'], $data['method'], $data['arguments']);
     } else {
         $result = MockMethodCalls::getInstance()->wasCalledCount($data['class'], $data['method']);
     }
     // test
     $this->assertEquals($data['expected'], $result);
 }
Esempio n. 7
0
 /**
  * @return void
  */
 public function test_function()
 {
     // prepare
     $traces = ['foo' => 1];
     $callArguments = ['bar' => 1];
     MockMethodCalls::init();
     $reflection = new \ReflectionClass('\\DbMockLibrary\\MockMethodCalls');
     $staticProperties = $reflection->getStaticProperties();
     $tracesProperty = $reflection->getProperty('traces');
     $tracesProperty->setAccessible(true);
     $tracesProperty->setValue($staticProperties['instance'], $traces);
     $callArgumentsProperty = $reflection->getProperty('callArguments');
     $callArgumentsProperty->setAccessible(true);
     $callArgumentsProperty->setValue($staticProperties['instance'], $callArguments);
     // invoke logic
     MockMethodCalls::getInstance()->reset();
     // test
     $this->assertEquals([], $tracesProperty->getValue($staticProperties['instance']));
     $this->assertEquals([], $callArgumentsProperty->getValue($staticProperties['instance']));
 }