Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 12th, 2012  |  syntax: PHP  |  size: 0.93 KB  |  views: 46  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. //Filename: MockeryABetterWayOfMockingTest.php
  3. require_once '../vendor/autoload.php';
  4.  
  5. class MockeryVersusPHPUnitGetMockTest extends PHPUnit_Framework_TestCase {
  6.    protected function tearDown() {
  7.       \Mockery::close();
  8.    }
  9.  
  10.    function testExpectOnce() {
  11.       $someObject = new SomeClass();
  12.  
  13.       // With PHPUnit
  14.       $phpunitMock = $this->getMock('AClassToBeMocked');
  15.       $phpunitMock->expects($this->once())->method('someMethod');
  16.  
  17.       // Exercise for PHPUnit
  18.       $someObject->doSomething($phpunitMock);
  19.  
  20.       // With Mockery
  21.       $mockeryMock = \Mockery::mock('AnInexistentClass');
  22.       $mockeryMock->shouldReceive('someMethod')->once();
  23.  
  24.       // Exercise for Mockery
  25.       $someObject->doSomething($mockeryMock);
  26.    }
  27. }
  28.  
  29. class AClassToBeMocked {
  30.    function someMethod() {}
  31. }
  32.  
  33. class SomeClass {
  34.    function doSomething($anotherObject) {
  35.       $anotherObject->someMethod();
  36.    }
  37. }
clone this paste RAW Paste Data