giorgiosironi / phpunit-selenium

Selenium RC integration for PHPUnit
http://www.phpunit.de/
Other
601 stars 271 forks source link

Class 'Tests\Selenium\PHPUnit_Extensions_Selenium2TestCase' not found #331

Closed kevincolten closed 9 years ago

kevincolten commented 9 years ago

Using Laravel, after installing

"phpunit/phpunit": "4.3.*",
"phpunit/phpunit-selenium": "1.4.*"

with composer, as per the phpunit docs, I get this error

Class 'Tests\Selenium\PHPUnit_Extensions_Selenium2TestCase' not found

when running this test

<?php

class LoginTest extends PHPUnit_Extensions_Selenium2TestCase {

  protected function setUp()
  {
    $this->setBrowser('firefox');
    $this->setBrowserUrl('http://localhost:8888/'); // set website being tested
  }

  /**
   * Recorded steps.
   */
  public function testSteps() {
    $test = $this; // Workaround for anonymous function scopes in PHP < v5.4.
    $session = $this->prepareSession(); // Make the session available.
    // get
    $this->url("http://localhost:8888");
    // waitForElementPresent
    $this->waitUntil(function() use ($test) {
      try {
        $boolean = ($test->byCssSelector("input[placeholder=\"Email Address\"]") instanceof \PHPUnit_Extensions_Selenium2TestCase_Element);
      } catch (\Exception $e) {
        $boolean = false;
      }
      return $boolean === true ?: null;
    });
    // assertElementPresent
    try {
      $boolean = ($test->byCssSelector("input[placeholder=\"Password\"]") instanceof \PHPUnit_Extensions_Selenium2TestCase_Element);
    } catch (\Exception $e) {
      $boolean = false;
    }
    $test->assertTrue($boolean);
  }
}

The class seems to be mapped in composer/autoload_classmap.php with 'PHPUnit_Extensions_Selenium2TestCase' => $vendorDir . '/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php' Any idea as to why it can't find the class?

kevincolten commented 9 years ago

Solved it by creating my phpunit.xml

<phpunit
    bootstrap="bootstrap/autoload.php"
    colors="true"
>
    <testsuites>
        <testsuite name="App Tests">
            <directory>app/tests</directory>
        </testsuite>
    </testsuites>
</phpunit>

thanks to this video Composer, Autoloading, Namespacing, and PHPUnit!