fixing error in creating mock

A public method became protected in phpunit
This commit is contained in:
Julien Fastré 2016-12-19 09:54:32 +01:00
parent 0899a931e4
commit c58d101ade
2 changed files with 18 additions and 13 deletions

View File

@ -30,8 +30,9 @@ use Symfony\Component\DomCrawler\Crawler;
* *
* @author Julien Fastré <julien.fastre@champs-libres.coop> * @author Julien Fastré <julien.fastre@champs-libres.coop>
*/ */
class CustomFieldTestHelper trait CustomFieldTestHelper
{ {
/** /**
* Prepare a crawler containing the rendering of a customField * Prepare a crawler containing the rendering of a customField
* *
@ -44,18 +45,20 @@ class CustomFieldTestHelper
* @param type $locale * @param type $locale
* @return Crawler * @return Crawler
*/ */
public static function getCrawlerForField(CustomField $field, KernelTestCase $testCase, KernelInterface $kernel, $locale = 'en') public function getCrawlerForField(CustomField $field, $locale = 'en')
{ {
//check a kernel is accessible $kernel = static::$kernel;
$customFieldsGroup = $testCase->getMock('Chill\CustomFieldsBundle\Entity\CustomFieldsGroup');
$customFieldsGroup->expects($testCase->once())
->method('getActiveCustomFields')
->will($testCase->returnValue(array($field)));
$request = $testCase->getMock('Symfony\Component\HttpFoundation\Request'); //check a kernel is accessible
$request->expects($testCase->any()) $customFieldsGroup = $this->createMock('Chill\CustomFieldsBundle\Entity\CustomFieldsGroup');
$customFieldsGroup->expects($this->once())
->method('getActiveCustomFields')
->will($this->returnValue(array($field)));
$request = $this->createMock('Symfony\Component\HttpFoundation\Request');
$request->expects($this->any())
->method('getLocale') ->method('getLocale')
->will($testCase->returnValue($locale)); ->will($this->returnValue($locale));
$kernel->getContainer()->get('request_stack')->push($request); $kernel->getContainer()->get('request_stack')->push($request);
@ -79,4 +82,4 @@ class CustomFieldTestHelper
return $crawler; return $crawler;
} }
} }

View File

@ -40,6 +40,8 @@ class CustomFieldsTextTest extends WebTestCase
*/ */
private $customFieldProvider; private $customFieldProvider;
use CustomFieldTestHelper;
public function setUp() public function setUp()
{ {
static::bootKernel(); static::bootKernel();
@ -67,7 +69,7 @@ class CustomFieldsTextTest extends WebTestCase
->setActive(true) ->setActive(true)
->setName(array('en' => 'my label')); ->setName(array('en' => 'my label'));
$crawler = CustomFieldTestHelper::getCrawlerForField($customField, $this, static::$kernel); $crawler = $this->getCrawlerForField($customField);
$this->assertCount(1, $crawler->filter("input[type=text]")); $this->assertCount(1, $crawler->filter("input[type=text]"));
$this->assertCount(1, $crawler->filter("label:contains('my label')")); $this->assertCount(1, $crawler->filter("label:contains('my label')"));
@ -83,7 +85,7 @@ class CustomFieldsTextTest extends WebTestCase
->setActive(true) ->setActive(true)
->setName(array('en' => 'my label')); ->setName(array('en' => 'my label'));
$crawler = CustomFieldTestHelper::getCrawlerForField($customField, $this, static::$kernel); $crawler = $this->getCrawlerForField($customField);
$this->assertCount(1, $crawler->filter("textarea")); $this->assertCount(1, $crawler->filter("textarea"));
$this->assertCount(1, $crawler->filter("label:contains('my label')")); $this->assertCount(1, $crawler->filter("label:contains('my label')"));