Skip to content

Instantly share code, notes, and snippets.

@giorrrgio
Last active December 19, 2015 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save giorrrgio/5918565 to your computer and use it in GitHub Desktop.
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
<?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