Note that there are some explanatory texts on larger screens.

plurals
  1. POPHPUnit 3.7.19 and Symfony2 broken tests
    primarykey
    data
    text
    <p>I'm developing some test for a Symfony2.0 project and running them with PHPUnit.</p> <p>On my PC works fine but trying them in other environments the tests fails. I thought the problem was php version but after run them in differents environments I'm lost.</p> <ul> <li><p>My environment is Ubuntu 12.04 and PHP 5.3.10 => <strong>Works fine.</strong></p></li> <li><p>2 PC with Ubuntu 12.10 and PHP 5.4.6:</p> <pre><code>Fatal error: Call to a member function get() on a non-object </code></pre></li> </ul> <p>This error is on a class which extends <strong>Symfony\Bundle\FrameworkBundle\Test\WebTestCase</strong> where is overwritten the setUp() and tearDown() methods.</p> <pre><code>public function setUp() { $this-&gt;client = static::createClient(); $this-&gt;client-&gt;followRedirects(true); $crawler = $this-&gt;client-&gt;request('GET', '/admin/login'); $loginForm = $crawler-&gt;selectButton('save')-&gt;form(array( '_username' =&gt; 'user', '_password' =&gt; 'pass' )); $this-&gt;client-&gt;submit($loginForm); $this-&gt;container = $this-&gt;client-&gt;getContainer(); parent::setUp(); } public function tearDown() { //Here is get() on a non-object, $this-&gt;container doesn't exists $this-&gt;container-&gt;get('doctrine.odm.mongodb.document_manager')-&gt;getConnection()-&gt;close(); parent::tearDown(); } </code></pre> <ul> <li><p>2 PC, one with Ubuntu 12.10 and PHP 5.4.6 and other with Windows 7 and PHP 5.3.8:</p> <pre><code>PHP Fatal error: Call to a member function getSite() on a non-object </code></pre></li> </ul> <p>This error is on a class which extends the above class that has tearDown() method wrong but in this case this class works and the error is different although is related with $this->container:</p> <pre><code>//In this case, the user doesn't exists $site = $this-&gt;container-&gt;get('security.context') -&gt;getToken()-&gt;getUser()-&gt;getSite(); </code></pre> <p>The problem is I don't know why is this. If this is related to PHP, PHPUnit(All of us have the same version), Symfony2.0 or SO.</p> <p><strong>Edit:</strong></p> <p>Ok, problems solved.</p> <p>First:</p> <pre><code>Fatal error: Call to a member function get() on a non-object </code></pre> <p>Had a wrong line of code in the class which has setUp() and tearDown() methods. A line like that:</p> <pre><code>$link = $crawler-&gt;filter('a:contains("Test")')-&gt;eq(1)-&gt;link(); </code></pre> <p>I had this line commented, sorry :). But I don't know why PHPUnit show me this error and not the error of link method.</p> <p>Second:</p> <pre><code>PHP Fatal error: Call to a member function getSite() on a non-object </code></pre> <p>In the others environments, the test database had not been deployed.</p> <p>This question will not help anyone but help me to try new things. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload