Skip to content

Instantly share code, notes, and snippets.

@mustafaileri
Created February 11, 2014 22:01
Show Gist options
  • Save mustafaileri/8945118 to your computer and use it in GitHub Desktop.
Save mustafaileri/8945118 to your computer and use it in GitHub Desktop.
Sample test with mock
<?php
/**
* User: Mustafa Ileri
* Date: 7/28/13
* Time: 11:29 PM
* Please type something...
*/
namespace Hezarfen\Bundle\CmsBundle\Tests\Service;
use Hezarfen\Bundle\CmsBundle\Service\CmsService;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class CmsServiceTest extends WebTestCase
{
public function testGetAll()
{
$client = static::createClient();
$modelMock = $this->getMockBuilder('Hezarfen\Bundle\CmsBundle\Model\CmsModel')
->setMethods(array('getAll'))->disableOriginalConstructor()->getMock();
$modelMock->expects($this->any())->method('getAll')->will($this->returnValue(array()));
$client->getContainer()->set('hezarfen_cms.model', $modelMock);
/** @var CmsService $cmsService */
$cmsService = $client->getContainer()->get('hezarfen_cms.service');
$this->assertTrue(is_array($cmsService->getAll()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment