Code Monkey home page Code Monkey logo

phpunit-mink's People

Contributors

aik099 avatar robertfausk avatar stof avatar vinai avatar yannkechichian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

phpunit-mink's Issues

Migration to "minkphp" organization

Recently the https://github.com/minkphp organization were created and all Mink-related repositories were moved there. I believe this repository is quite Mink-related as well to be moved there as well.

Here are some specifics about this repo:

  1. it uses it's own documentation http://phpunit-mink.readthedocs.org/en/latest/ so no shared documentation with https://mink.readthedocs.org/en/latest/ I guess
  2. it uses own coding standard (https://github.com/aik099/CodingStandard) which uses TABs for indentation
  3. it uses my personal accounts (encrypted using current repo ID in .travis.yml) for testing SauceLabs and BrowserStack services (I'm not sure if either of services allows for personal open-source account usage in another GitHub organization)
  4. because PHP_CodeSniffer on Scrutinizer CI is still 1.5 the inspection fails on Fatal Error (because coding standard uses classes added in PHP_CodeSniffer 2.0)
  5. the package name on Composer will stay the same for existing users to be happy
  6. probably need to contact both Scrutinizer CI and Coveralls.IO to make them rename the repo or otherwise I will loose all the past inspections

//cc @stof

Remove dependency on Pimple

I've tried to use phpunit-mink with my Silex application, but stumbled upon a roadblock. Silex 1.2 (current stable) uses Pimple ~1.0 while phpunit-mink requires Pimple 2.0 or upper. Composer is not able to resolve the conflicts, as Pimple public interface has changed.

My idea is to remove dependency on Pimple in Composer to avoid conflicts. Some ways I see it can be done:

  • copy Pimple code into phpunit-mink repo (quick fix, but hacky)
  • use git submodule to attach Pimple 2.0 code (not sure if Composer supports that)
  • refactor DIContainer so it does not depend on Pimple functionality

Personally I'm in favor of Dependency Inversion, but libraries depending on Dependency Injection Container are hard to integrate due to such issues. Let me know your thoughts.

Create BrowserConfiguration in BrowserTestSuite

Right now BrowserConfiguration is created for each test in a testcase (new object) even if we know ahead, that all tests in a test case will be using same configuration (via $browsers static class property).

Need to move that up to BrowserTestSuite class.

BrowserConfiguration improvements

  1. validate if unknown setting is given and throw an exception
  2. don't validate session strategy at all, since SessionStrategyFactory will do that anyway

baseUrl not working

The baseUrl I set in the static $browsers variable does not have any effect. Take this example:

<?php
namespace AppBundle\Tests\Controller;

use aik099\PHPUnit\BrowserTestCase;

class WhateverControllerTest extends BrowserTestCase
{

    public static $browsers = [
        [
            'driver' => 'selenium2',
            'baseUrl' => 'http://www.google.com',
            'port' => 8643
        ]
    ];

    public function testAbc()
    {
        $this->getSession()->visit('/');
        die($this->getSession()->getPage()->getContent());
    }

}

?>

This gives me an output like this:

<html><head></head><body></body></html>

However, if I change the argument I pass to visit() to something like http://www.google.com instead, everything works as expected.

Mink Zombie driver isn't working

Just trying to run my phpunit tests through Mink and Zombie driver. Here is my config

array(
            'driver' => 'zombie',

            // Defaults for this driver
            'port' => 8124,
            'driverOptions' => array(
                'node_bin' => 'node',
                'server_path' => null,
                'threshold' => 2000000,
                'node_modules_path' => '/Users/path to/node_modules/',
            ),
        ),

I have installed zombie locally with npm and exported NODE_PATH in my .zshrc

When I run my test I get following

PHPUnit 4.5.1 by Sebastian Bergmann and contributors.

E

Time: 4.12 seconds, Memory: 6.75Mb

There was 1 error:

1) BrandingHomeTest::testHomePage
RuntimeException: Server did not respond in time: () [Stopped]

/Users//vendor/behat/mink-zombie-driver/src/Behat/Mink/Driver/NodeJS/Server.php:399
/Users//vendor/behat/mink-zombie-driver/src/Behat/Mink/Driver/NodeJS/Server.php:300
/Users//vendor/behat/mink-zombie-driver/src/Behat/Mink/Driver/ZombieDriver.php:78
/Users/vendor/behat/mink/src/Session.php:70
/Users//vendor/aik099/phpunit-mink/library/aik099/PHPUnit/Session/IsolatedSessionStrategy.php:79
/Users/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php:289
/Users/HomeTest.php:11
/Users/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php:371
/Users/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php:319

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.

I am not sure if I am missing any config ?

Have someone tried that ?

[bc break] Remove "Selenium" dependency

Currently the Selenium dependency is hardcoded:

  • the selenium Mink driver is a requirement in composer.json
  • the timeout and desiredCapabilities settings in BrowserConfiguraiton only apply to Selenium

After #12 is implemented we can, but this will be BC break for sure:

  • replace selenium requirement in composer.json with suggest tag, that Mink itself uses
  • move desiredCapabilities and timeout from global BrowserConfiguration options to Selenium2 driver specific options
  • set empty default driver
  • upon attempt to create driver without actual driver name set throw an exception

Error when using Dataprovider

Hi there,

I am getting with v2.0.0 the error

Fatal error: Call to undefined method PHPUnit_Framework_TestSuite_DataProvider::setEventDispatcher() in [snip]\vendor\aik099\phpunit-mink\library\aik099\PHP
Unit\TestSuite\AbstractTestSuite.php on line 91

Here is my test:

<?php

namespace Tests;

use aik099\PHPUnit\BrowserTestCase;

/**
 * Description of testCrossBrowserLayout
 *
 * @author KEH
 */
class CrossBrowserLayoutTest extends BrowserTestCase {

    public static $browsers = array(
        array(
        'host' => 'localhost',
        'port' => 4444,
        'browserName' => 'firefox',
        'baseUrl' => 'http://www.google.com',
        ),
    );

    public function testPageProvider() {
        // parse your data file however you want
        $data = array();
        $data[] = array(
            'pageid' => 'A0001',
            'pagename' => 'home.htm',
            'pagetype' => 'MAS'
        );
        return $data;
    }

    /**
     * @dataProvider testPageProvider
     */
    public function testPushAndPop($page) {
        $this->assertTrue($page['pageid'] == 'A0001');
    }

}

I really need the data provider to crawl through several pages and execute tests on them.
Can you help out?

Configurable session termination

Currently, the created session is terminated using the stop method which closes the browser completely and reopens it when the next session is created.

This takes a lot of time. If there is no need for such restriction (session creation for each test/test case), then we need to be able to use the reset method, which would only clear browser cookies.

Then we also need to visit the base URL (no matter what) on each session creation to ensure that any visual state of the last visited page is reset as well (e.g. checkbox sticky state for example, where page reload doesn't uncheck checkboxes).


The draft name for this functionality is soft isolated session strategy.

Simplify DocBlocks in test suite

Coding standard allows to skip DocBlocks completely in test suite and that's why we can:

  1. remove
/**
 * Test description.
 *
 * @return void
 */
  1. remove any not-needed parts of DocBlocks (e.g. keep only @expects... tags)

Create proxy around Mink's Session

Right now call to BrowserTestCase::getSession() will not only create session, but also start it automatically. The auto-start behavior comes from IsolatedSessionStategy.

This behavior might not be desired one, because browser is opened even before any user code, that interacts with it is started.

I think that we can create proxy around Session class, that would ignore explicit calls to start method and will auto-start (if not running) on call to ->visit method.

Remove PHPUnit dependency from `composer.json`

Right now there a dependency on PHPUnit in composer.json which:

  • from one side is correct (library creates a test case class for PHPUnit)
  • from other side is not (it's forcing local PHPUnit copy in project even if PHPUnit is installed globally on machine and used from there)

@stof , can we just remove PHPUnit dependency?

Inline "SessionFactory" class

After #12 is implemented the session driver creation is moved away from SessionFactory class to the corresponding driver factories. And the SessionFactory only has 1 line long method called createSession:
phpunitmink_smallsessionfactory

The only class using that method is IsolatedSessionStrategy that can create/start sessions. I propose, that we:

  • remove ISessionFactory interface
  • remove SessionFactory class
  • inline SessionFactory::createSession method into IsolatedSessionStrategy::session method

Create integration tests

Create tests that would verify, that all events dispatched across the system during test execution, are received by whoever has subscribed to them.

Improve extensibility

Framework extensibility needs to be improved. To do that we need to:

  • introduce EventDispatcher for cross-object communications
  • move away all sort of new object instantiations into factory classes
  • use DIC to keep actual used class names in 1 place only

Test, that dispatched event is only received by recipient

Before recipient check it happened, that upon first test ended all tests received the "test.ended" event and stopped their sessions.

To solve that problem we now check that a BrowserConfiguration which received an event has same test case object attached to it, that one which sent the event.

Such behavior however isn't covered by tests.

Stopping sessions from BrowserConfigiration

Right now BrowserConfiguration::createSession method allows to create a new session (no auto-start) based on browser configuration.

To implement #5 it would be great to:

  1. set session termination mode right in browser configuration
  2. add BrowserConfiguration::terminateSession method, that would (according to termination setting) stop or reset given session.

shared sessionStrategy: UnknownError when getSession() called in second test method

I am running tests with PHPUnit, using Mink to write acceptance tests.

I have come across the error when modifying the "GeneralTest" class given in the examples.

To reproduce:

  1. I add this to the $browser array: 'sessionStrategy' => 'shared'
  2. I copy the method testUsingSession() and paste as testUsingSession2()

For now, the only workaround I have is to omit the shared session declaration and have a new browser window load for each test method (unnecessarily slow).

The "SuiteBuildingTest::testSuiteTearDown" fails on PHPUnit 4.6+

In the PHPUnit 4.6 the TestSuite::setDisallowChangesToGlobalState method was added and is called during test suite run. During testing the test suite class is being mocked, but since it's unaware about this new method being called this all ends up in failing test with this error:

1) tests\aik099\PHPUnit\Integration\SuiteBuildingTest::testSuiteTearDown
BadMethodCallException: Method Mockery_19_aik099_PHPUnit_TestSuite_BrowserTestSuite::setDisallowChangesToGlobalState() does not exist on this mock object

/home/user/phpunit-mink/tests/aik099/PHPUnit/Integration/SuiteBuildingTest.php:86
/home/user/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:149
/home/user/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:100

The tests on travis that passed were executed using PHPUnit 4.5 version.

Support Pimple 3.0

Pimple 3 is stable (it is basically Pimple 2 without the BC layer for the old Pimple name as this BC layer was impossible to provide in the C extension).
The requirement should allow using it (if the library uses the Pimple\Container name everywhere, it should be a matter of changing the constraint to ~2|~3)

Failed to use shared session strategy

Hi,
I found a bug about SharedSessionStrategy.

At 131 lines in SharedSessionStrategy.php file, $this->_session->switchToWindow() has no parameters. This will cause Selenium2 throws an exception if I use shared strategy.

After I change this line to $this->_session->switchToWindow($this->_session->getWindowName()), it works.

So please fix this bug. Thanks.

PS. Blow is the error details

WebDriver\Exception\UnknownError: unknown error: 'name' must be a nonempty string
  (Session info: chrome=46.0.2490.86)
  (Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Linux 3.13.0-32-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 3 milliseconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'ubuntu', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-32-generic', java.version: '1.7.0_75'
Session ID: 82b9bf3f777bba7a5bc3c73f322bc90a
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/tmp/.com.google.Chrome.x7DP64}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=46.0.2490.86, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]

/home/litb/workspace/browser_test/vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:155
/home/litb/workspace/browser_test/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php:140
/home/litb/workspace/browser_test/vendor/instaclick/php-webdriver/lib/WebDriver/Session.php:273
/home/litb/workspace/browser_test/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:407
/home/litb/workspace/browser_test/vendor/behat/mink/src/Session.php:304
/home/litb/workspace/browser_test/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/Session/SharedSessionStrategy.php:131
/home/litb/workspace/browser_test/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/Session/SharedSessionStrategy.php:103
/home/litb/workspace/browser_test/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php:289
/home/litb/workspace/browser_test/tests/LoginTest.php:69
/home/litb/workspace/browser_test/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php:371
/home/litb/workspace/browser_test/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php:319

Update license text in each file

Current license says:

/**
 * This file is part of the phpunit-mink library.
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 *
 * @copyright Alexander Obuhovich <[email protected]>
 * @link      https://github.com/aik099/phpunit-mink
 */

The repo url is wrong and maybe something needs to be done about @copyright tag, but I'm not sure what.

@stof , ideas?

Add the "BrowserTestCase::prepareUrl" convinience method

I've had an interesting use case reported in #51 today: the value of baseUrl setting in browser configuration isn't applied when $this->getSession()->visit('/some/relative/path') call is made.

The person was most likely working with Behat/MinkExtension before and expected similar to happen here as well. Of course this won't work in this library due absence of Gherkin or similar language that later would be transformed into actual PHP code. Here PHP code is written directly.

If there a need, then maybe the prepareUrl($url) protected method needs to be added to the test case class, that would:

  • parse given url
  • if it's a relative url, then prepend value from baseUrl setting in browser configuration
  • if it's an absolute url, then return as is

We can actually take these methods from MinkExtension itself.


I'm not sure if this is feature, that will be widely adopted among library users though.

Session is reset after failing test?

I have multiple test methods with shared sessionStrategy. In the first test, i visit my URL. If this test is passing, the other tests work as well. Otherwise, the session is reset to a blank page. Maybe it's a feature, not a bug? But I think it should be saved.

Code:

class ExampleTest extends BrowserTestCase
{

    public static $browsers = array(
        array(
            'driver' => 'selenium2',
            'host' => 'localhost',
            'port' => 4444,
            'browserName' => 'firefox',
            'baseUrl' => 'http://localhost',
            'sessionStrategy' => 'shared'
        ),
    );

    public function test1()
    {   
        $session = $this->getSession();
        $session->visit( 'http://localhost/test' );
        $this->assertTrue( 1 == 2 );
    }

    public function test2()
    {
        // blank page if test1 is failing
        file_put_contents('/tmp/screenshot.png', $this->getSession()->getDriver()->getScreenshot());

    }

}

Documentation is not clear or incorrect

Example in section #per-test-configuration produce error: Fatal error: Call to a member function createBrowserConfiguration() on a non-object in blabla/vendor/aik099/phpunit-mink/library/aik099/PHPUnit/BrowserTestCase.php on line 242

As I understood from the code, developer should set instance of BrowserConfigurationFactory for BrowserTestCase first?!

Refactor "BrowserConfigurationFactory::createAPIClient"

Refactor BrowserConfigurationFactory::createAPIClient in a way, that we'll end up in abstract ApiBrowserConfiguration::createAPIClient and each sub-class would create needed client as it see fits.

Proposed change would allow to remove dependency of ApiBrowserConfiguration descendant classes to the BrowserConfigurationFactory.

See https://github.com/minkphp/phpunit-mink/blob/master/library/aik099/PHPUnit/BrowserConfiguration/BrowserConfigurationFactory.php#L100-L116

Don't merge associated PR before #40, because there method is made public.

[Suggestion] Use coding standards consistent with other Mink libraries

The other Mink libraries are using the Symfony2 coding standards, which are a superset of PSR-2.
The current coding standards are conflicting with PSR-2, making it harder for new contributors to get them right (and forcing more experienced contributors to reconfigure their IDEs when switching to this project).
I identified 2 main violations of PSR-2 in the current coding standards:

  • tabs instead of spaces for the indentation
  • snake cased variable names instead of camel cased ones.
  • leading underscores in private properties (not sure whether PSR-2 defines it, but the Symfony standard used by Mink does)

I haven't reviewed everything in depth to build an exhaustive list though.

Note that a nice thing when using the PSR-2 coding standard is that the PHP-CS-Fixer can be used to fix many violations automatically (instead of just complaining in PHPCS). this is how I ensure the consistent coding standards on other Mink repos (the PHP-CS-Fixer also handles many Symfony-specific rules on top of PSR-2 btw).

Remember all sessions, created from BrowserConfiguration

Make BrowserConfiguration::createSession method to remember each created session somewhere in central place (shared between browser configurations).

Then via register_shutdown_function ensure, that all sessions are stopped. This would save the day when #5 will be implemented, because we'll have 1 session per browser which is only reset (not stopped) in each test/test case.

Don't start session based on coverage collection flag

Currently session is started automatically (to put tracking cookie in it) during test run when coverage collection is enabled.

We should only start session when remote coverage collection is enabled (which by the way is disabled by default).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.