Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A helper method to save Symfony Client content to an html file and immediately open the page on your browser
<?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();
}
}
}
<?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);
}
}
}
}
<?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