php - What is wrong with my FeatureContext? -


i believe not clear on behatcontext versus minkcontext , not sure why inherit 1 or other in app. not clear on why have instantiate new client object in every function. should able use $this since have goutte loaded in behat.yml file.

any tips please?

<?php  namespace main\referralcapturebundle\features\context;  use main\referralcapturebundle\features\context\featurecontext;  use symfony\component\httpkernel\kernelinterface; use behat\symfony2extension\context\kernelawareinterface; use behat\minkextension\context\minkcontext; use behat\minkextension\context\rawminkcontext;  use behat\behat\context\behatcontext,     behat\behat\exception\pendingexception; use behat\gherkin\node\pystringnode,     behat\gherkin\node\tablenode;  use goutte\client;  // // require 3rd-party libraries here: //    require_once 'phpunit/autoload.php';    require_once 'phpunit/framework/assert/functions.php'; //  /**  * feature context.  */ class featurecontext extends rawminkcontext //minkcontext if want test web                   implements kernelawareinterface {     private $kernel;     private $parameters;      /**      * initializes context parameters behat.yml.      *      * @param array $parameters      */     public function __construct(array $parameters)     {         $this->parameters = $parameters;         $this->usecontext('behat', new behatcontext);         $this->usecontext('mink', new minkcontext);     }      /**      * sets httpkernel instance.      * method automatically called symfony2extension contextinitializer.      *      * @param kernelinterface $kernel      */     public function setkernel(kernelinterface $kernel)     {         $this->kernel = $kernel;     }        /**      * @given /^i on homepage$/      */     public function iamonhomepage()     {        // $this->getsession()->visit("/");          $client = new client();         $crawler = $client->request('get', 'http://local.referral.com/');          $link = $crawler->selectlink('i physician')->link();          if (!count($link)>0)        {           throw new exception("home page not loaded:\n");            }      }      /**      * @given /^i follow "([^"]*)"$/      */     public function ifollow($arg1)     {         $client = new client();         $crawler = $client->request('get', 'http://local.referral.com/');         $link = $crawler->selectlink('register')->link();        $crawler = $client->click($link);               }      /**      * @when /^i fill in "([^"]*)" "([^"]*)"$/      */     public function ifillinwith($arg1, $arg2)     {         throw new pendingexception();     }      /**      * @given /^i press "([^"]*)"$/      */     public function ipress($arg1)     {         throw new pendingexception();     }      /**      * @then /^i should see "([^"]*)"$/      */     public function ishouldsee($arg1)     {         throw new pendingexception();     }      /**      * @given /^i should on homepage$/      */     public function ishouldbeonhomepage()     {         throw new pendingexception();     }       } 

i believe not clear on behatcontext versus minkcontext , not sure why inherit 1 or other in app.

behatcontext basic context default choice of own contexts.

minkcontext specialized context giving access mink session. contains basic step definitions. that's why should never extend ('cause you'd able extend once, since step definitions cannot duplicated).

if need access mink session extend rawminkcontext. it's minkcontext without step definitions.

basically not clear on why have instantiate new client object in every function. should able use $this since have goutte loaded in behat.yml file.

why trying instantiate client yourself? use mink session, you:

<?php  namespace main\referralcapturebundle\features\context;  // use statements here...  class featurecontext extends rawminkcontext {             /**      * @given /^i on homepage$/      */     public function iamonhomepage()     {         $session = $this->getsession();         $session->visit($this->locatepath('/'));          $link = $session->getpage()->findlink('i physician');         if (null === $link) {           throw new exception("home page not loaded:\n");           }     }      /**      * @given /^i follow "([^"]*)"$/      */     public function ifollow($arg1)     {         $link = $this->getsession()->findlink('register');          if (null === $link) {             throw new \logicexception('could not find "register" link');         }          $link->click();                         }       // ...    } 

look @ step definitions in minkcontext inspiration.

to read (seriously, read docs first):


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -