Propel 쿼리를 사용하는 클래스에 단위 테스트 (phpunit 및 mockery 사용)를 쓰려고합니다.
검색어를 모의 표시하려면 어떻게합니까? $contact = ClientContactQuery::create()->findPK($id);
함수에서 Propel 쿼리 조롱 (symfony2)
나는 이것에 대한 예제를 찾기 위해 고심 중입니다.
내 수업;
<?php
namespace MyBundle\Classes;
use MyBundle\Model\ClientContactQuery;
use MyBundle\Model\ClientContact;
class Contacts {
protected $_cache;
public function __construct($cache)
{
$this->_cache = $cache;
}
public function getContact($id)
{
$contact = ClientContactQuery::create()->findPK($id);
if (! $contact) {
throw new NotFoundHttpException('Client contact not found.');
}
return $contact;
}
}
내 테스트 사례
<?php
namespace MyBundle\Tests\Classes;
use Mockery as m;
use MyBundle\Classes\Contacts as c;
class ContactsTest extends \PHPUnit_Framework_TestCase
{
public function tearDown()
{
m::close();
}
public function testGetValidContact()
{
// Arrange
$cache = m::mock('cache');
// Act
$contact = new c($cache);
// am lost at this point :-(
// Assert
$this->assertInstanceOf('MyBundle\Classes\Contacts', $contact);
}
}