Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. class RepositoryControllerTest extends \PHPUnit_Framework_TestCase
  2. {
  3.  
  4.     function tearDown()
  5.     {
  6.         \Mockery::close();
  7.     }
  8.  
  9.     public function testGetAllAction()
  10.     {
  11.  
  12.         $request = \Mockery::mock( 'Symfony\Component\HttpFoundation\Request' );
  13.  
  14.         $app = \Mockery::mock( 'Silex\Application' );
  15.  
  16.         $expected_results = [ ]; // you know this
  17.  
  18.         $db = \Mockery::mock( '\Doctrine\Common\Persistence\ObjectManager' );
  19.         $db->shouldReceive( 'getRepository->createQueryBuilder->setFirstResult->setMaxResults->getQuery->getResult' )
  20.             ->andReturn( $expected_results );
  21.  
  22.          // in RepositoryController use $app->offsetGet('em') instead of $app['em'];
  23.         $app->shouldReceive( 'offsetGet' )->with( 'em' )->andReturn( $db );
  24.  
  25.         $controller = new RepositoryController( $request, $app );
  26.  
  27.         $this->assertSame( json_encode( $expected_results ), $controller->getAllAction() );
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement