You are here

class BestPracticesTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/behat/mink/driver-testsuite/tests/Basic/BestPracticesTest.php \Behat\Mink\Tests\Driver\Basic\BestPracticesTest

This testcase ensures that the driver implementation follows recommended practices for drivers.

Hierarchy

  • class \Behat\Mink\Tests\Driver\TestCase extends \Behat\Mink\Tests\Driver\PHPUnit_Framework_TestCase

Expanded class hierarchy of BestPracticesTest

File

vendor/behat/mink/driver-testsuite/tests/Basic/BestPracticesTest.php, line 10

Namespace

Behat\Mink\Tests\Driver\Basic
View source
class BestPracticesTest extends TestCase {
  public function testExtendsCoreDriver() {
    $driver = $this
      ->createDriver();
    $this
      ->assertInstanceOf('Behat\\Mink\\Driver\\CoreDriver', $driver);
    return $driver;
  }

  /**
   * @depends testExtendsCoreDriver
   */
  public function testImplementFindXpath() {
    $driver = $this
      ->createDriver();
    $this
      ->assertNotImplementMethod('find', $driver, 'The driver should overwrite `findElementXpaths` rather than `find` for forward compatibility with Mink 2.');
    $this
      ->assertImplementMethod('findElementXpaths', $driver, 'The driver must be able to find elements.');
    $this
      ->assertNotImplementMethod('setSession', $driver, 'The driver should not deal with the Session directly for forward compatibility with Mink 2.');
  }

  /**
   * @dataProvider provideRequiredMethods
   */
  public function testImplementBasicApi($method) {
    $driver = $this
      ->createDriver();
    $this
      ->assertImplementMethod($method, $driver, 'The driver is unusable when this method is not implemented.');
  }
  public function provideRequiredMethods() {
    return array(
      array(
        'start',
      ),
      array(
        'isStarted',
      ),
      array(
        'stop',
      ),
      array(
        'reset',
      ),
      array(
        'visit',
      ),
      array(
        'getCurrentUrl',
      ),
      array(
        'getContent',
      ),
      array(
        'click',
      ),
    );
  }
  private function assertImplementMethod($method, $object, $reason = '') {
    $ref = new \ReflectionClass(get_class($object));
    $refMethod = $ref
      ->getMethod($method);
    $message = sprintf('The driver should implement the `%s` method.', $method);
    if ('' !== $reason) {
      $message .= ' ' . $reason;
    }
    $this
      ->assertSame($ref->name, $refMethod
      ->getDeclaringClass()->name, $message);
  }
  private function assertNotImplementMethod($method, $object, $reason = '') {
    $ref = new \ReflectionClass(get_class($object));
    $refMethod = $ref
      ->getMethod($method);
    $message = sprintf('The driver should not implement the `%s` method.', $method);
    if ('' !== $reason) {
      $message .= ' ' . $reason;
    }
    $this
      ->assertNotSame($ref->name, $refMethod
      ->getDeclaringClass()->name, $message);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BestPracticesTest::assertImplementMethod private function
BestPracticesTest::assertNotImplementMethod private function
BestPracticesTest::provideRequiredMethods public function
BestPracticesTest::testExtendsCoreDriver public function
BestPracticesTest::testImplementBasicApi public function @dataProvider provideRequiredMethods
BestPracticesTest::testImplementFindXpath public function @depends testExtendsCoreDriver
TestCase::$config private static property
TestCase::$mink private static property Mink session manager.
TestCase::checkRequirements protected function
TestCase::createDriver protected function Creates a new driver instance.
TestCase::findById protected function
TestCase::getAssertSession protected function Returns assert session.
TestCase::getConfig private static function
TestCase::getSession protected function Returns session.
TestCase::mapRemoteFilePath protected function Map remote file path.
TestCase::onNotSuccessfulTest protected function
TestCase::pathTo protected function
TestCase::safePageWait protected function Waits for a condition to be true, considering than it is successful for drivers not supporting wait().
TestCase::setUpBeforeClass public static function Initializes the test case.
TestCase::tearDown protected function