Last active
December 19, 2015 07:28
-
-
Save giorrrgio/5918565 to your computer and use it in GitHub Desktop.
A helper method to save Symfony Client content to an html file and immediately open the page on your browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyNamespace\CoreBundle\Test; | |
use Symfony\Bundle\FrameworkBundle\Client; | |
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as SymfonyWebTestCase; | |
use Symfony\Component\Process\Process; | |
abstract class WebTestCase extends SymfonyWebTestCase | |
{ | |
public function saveOutput(Client $client, $path = null, $domain = null, $browser = 'firefox') | |
{ | |
if (is_null($path)) { | |
$path = "/../../../../web/test_out.html"; | |
} | |
file_put_contents(__DIR__ . $path, $client->getResponse()->getContent()); | |
if (!is_null($domain)) { | |
$process = new Process($browser . ' "'.$domain.'/test_out.html"'); | |
$process->run(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyNamespace\CoreBundle\Test; | |
use Symfony\Bundle\FrameworkBundle\Client; | |
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as SymfonyWebTestCase; | |
use Symfony\Component\Process\Process; | |
abstract class WebTestCase extends SymfonyWebTestCase | |
{ | |
public function saveOutput(Client $client, $path = null, $domain = null, $delete = true, $browser = 'firefox') | |
{ | |
if (is_null($path) || '' == $path) { | |
$path = "/../../../../web/test_out.html"; | |
} | |
file_put_contents(__DIR__ . $path, $client->getResponse()->getContent()); | |
if (!is_null($domain)) { | |
$process = new Process($browser . ' "'.$domain.'/test_out.html"'); | |
$process->start(); | |
sleep(1); | |
if ($delete) { | |
unlink(__DIR__ . $path); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyNamespace\CoreBundle\Test; | |
use Symfony\Bundle\FrameworkBundle\Client; | |
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as SymfonyWebTestCase; | |
use Symfony\Component\Process\Process; | |
abstract class WebTestCase extends SymfonyWebTestCase | |
{ | |
public function saveOutput(Client $client, $path = null, $domain = null, $delete = true, $browser = 'firefox') | |
{ | |
if (is_null($path) || '' == $path) { | |
$path = "/../../../../web/test_out.html"; | |
} | |
file_put_contents(__DIR__ . $path, $client->getResponse()->getContent()); | |
if (!is_null($domain)) { | |
$process = new Process($browser . ' "'.$domain.'/test_out.html"'); | |
$process->run(function() use($path, $delete) { | |
if ($delete) { | |
unlink(__DIR__ . $path); | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment