I finally ended up inheriting my test class from that class:
<?php
class MultiDomainCase extends TestCase
{
protected $domain;
public function setUp()
{
if (!empty($this->domain) || !is_null($this->domain))
{
$configuration = $this->getConfiguration();
$configuration['url'] = $this->domain;
$this->saveConfiguration($configuration);
}
parent::setUp();
}
public function tearDown()
{
if (!empty($this->domain) || !is_null($this->domain))
{
$configuration = $this->getConfiguration();
// TODO revert to initial version
$configuration['url'] = 'http://localhost/';
$this->saveConfiguration($configuration);
}
parent::tearDown();
}
private function getConfiguration()
{
$configurationFilePath = __DIR__.'/../config/testing/app.php';
if (file_exists($configurationFilePath))
return require $configurationFilePath;
return null;
}
private function saveConfiguration($configuration)
{
$configurationFilePath = __DIR__.'/../config/testing/app.php';
$content = '<?php return ' . var_export($configuration, true) . ';';
file_put_contents($configurationFilePath, $content);
}
}
The test class would look like this:
<?php
require_once(__DIR__.'/../MultiDomainCase.php');
class DomainTest extends MultiDomainCase
{
protected $domain = 'http://some.website.com/';
public function testDomainHomepage()
{
// Given
// When
$crawler = $this->client->request('GET', 'http://some.website.com/');
// Then
$this->assertTrue($this->client->getResponse()->isOk());
}
}
Now I can test my subdomains.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community