{"id":20827687,"url":"https://github.com/peridot-php/peridot-scope-example","last_synced_at":"2026-04-28T04:36:36.372Z","repository":{"id":22108555,"uuid":"25438970","full_name":"peridot-php/peridot-scope-example","owner":"peridot-php","description":"Demonstrating child scopes in Peridot by mixing in webdriver capabilities","archived":false,"fork":false,"pushed_at":"2015-03-18T14:13:27.000Z","size":132,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-18T17:56:57.036Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://peridot-php.github.io/#scopes","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peridot-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-19T20:19:47.000Z","updated_at":"2016-07-31T00:07:43.000Z","dependencies_parsed_at":"2022-08-19T09:11:14.517Z","dependency_job_id":null,"html_url":"https://github.com/peridot-php/peridot-scope-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-scope-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-scope-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-scope-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-scope-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peridot-php","download_url":"https://codeload.github.com/peridot-php/peridot-scope-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243175270,"owners_count":20248445,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T23:12:45.636Z","updated_at":"2025-12-27T07:38:44.402Z","avatar_url":"https://github.com/peridot-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Peridot Scope Example\n=====================\n\nThis repo demonstrates using custom scopes to mix in test functionality for the [Peridot](https://github.com/peridot-php/peridot) testing framework for PHP.\n\nRead more [here](http://peridot-php.github.io/#scopes).\n\n##The custom scope\n\nWe first create a class that extends `Scope` so we can mix in functionality to our tests:\n\n```php\n\u003c?php // src/Example/WebDriverScope\nnamespace Peridot\\Example;\n\nuse Evenement\\EventEmitter;\nuse Peridot\\Core\\Scope;\n\nclass WebDriverScope extends Scope\n{\n    /**\n     * @var \\RemoteWebDriver\n     */\n    protected $driver;\n\n    /**\n     * @var \\Evenement\\EventEmitter\n     */\n    protected $emitter;\n\n    /**\n     * @param \\RemoteWebDriver $driver\n     */\n    public function __construct(\\RemoteWebDriver $driver, EventEmitter $emitter)\n    {\n        $this-\u003edriver = $driver;\n        $this-\u003eemitter = $emitter;\n\n        //when the runner has finished lets quit the driver\n        $this-\u003eemitter-\u003eon('runner.end', function() {\n            $this-\u003edriver-\u003equit();\n        });\n    }\n\n    /**\n     * Add a getPage method to our tests\n     *\n     * @param $url\n     */\n    public function getPage($url)\n    {\n        $this-\u003edriver-\u003eget($url);\n    }\n\n    /**\n     * Adds a findElementById method to our tests\n     *\n     * @param $id\n     * @return \\WebDriverElement\n     */\n    public function findElementById($id)\n    {\n        return $this-\u003edriver-\u003efindElement(\\WebDriverBy::id($id));\n    }\n}\n```\n\n##Configuring Peridot\n\nWe can mix in our `WebDriverScope` via the Peridot configuration file:\n\n```php\n\u003c?php // peridot.php\nuse Peridot\\Core\\Suite;\nuse Peridot\\Example\\WebDriverScope;\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\nreturn function($emitter) {\n\n    //create a single WebDriverScope to port around\n    $driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', array(\n        WebDriverCapabilityType::BROWSER_NAME =\u003e WebDriverBrowserType::FIREFOX\n    ));\n    $webDriverScope = new WebDriverScope($driver, $emitter);\n\n    /**\n     * We want all suites and their children to have the functionality provided\n     * by WebDriverScope, so we hook into the suite.start event. Suites will pass their child\n     * scopes to all child tests and suites.\n     */\n    $emitter-\u003eon('suite.start', function(Suite $suite) use ($webDriverScope) {\n        $scope = $suite-\u003egetScope();\n        $scope-\u003eperidotAddChildScope($webDriverScope);\n    });\n};\n```\n\n##Using mixed in behavior\n\nBy mixing in scopes, we can use the methods provided by them:\n\n```php\n\u003c?php\ndescribe('The home page', function() {\n    it('should have a greeting', function() {\n        $this-\u003egetPage('http://localhost:4000');\n        $greeting = $this-\u003efindElementById('greeting');\n        assert($greeting-\u003egetText() === \"Hello\", \"should be Hello\");\n    });\n});\n```\n\n##Running the tests\n\nYou will need a selenium server running, and you will want to run the `web` directory. Thankfully, running selenium is a snap using [webdriver-manager](https://github.com/peridot-php/webdriver-manager). From the project root:\n\n```\n$ vendor/bin/manager start\n```\n\nthen fire up the built-in PHP server:\n\n```\n$ php -S localhost:4000 -t web/\n```\n\nthen run peridot tests:\n\n```\n$ vendor/bin/peridot specs/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperidot-php%2Fperidot-scope-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperidot-php%2Fperidot-scope-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperidot-php%2Fperidot-scope-example/lists"}