phpunit-mink icon indicating copy to clipboard operation
phpunit-mink copied to clipboard

Add the "BrowserTestCase::prepareUrl" convinience method

Open aik099 opened this issue 10 years ago • 2 comments

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.

aik099 avatar Apr 07 '15 14:04 aik099

Note that $this->getSession()->visit('/some/relative/path') does not apply the base path either in MinkExtension. There is 2 ways to have the base path applied:

// MinkExtension 1.x or 2.x:
$this->getSession()->visit($this->locatePath('/some/relative/path'));

// MinkExtension 2.x shortcut (using the code above internally)
$this->visit('/some/relative/path');

stof avatar Apr 07 '15 14:04 stof

Yes, separate visit method, that would translate relative paths was my 2nd idea, but I wasn't sure if that won't create any more confusion knowing that $this->getSession() provides direct session access.

@parhamdoustdar, if you would like, then you can send PR for that feature (described above).

aik099 avatar Apr 07 '15 14:04 aik099