Skip to content

Instantly share code, notes, and snippets.

@yuya-takeyama
Created March 24, 2012 09:58
Show Gist options
  • Save yuya-takeyama/2180749 to your computer and use it in GitHub Desktop.
Save yuya-takeyama/2180749 to your computer and use it in GitHub Desktop.
What's Test Spy?
<?php
namespace Example\Application\Tests;
use \Example\Application;
use \SymfonyX\Component\Console\Output\SpyOutput;
class ApplicationTest extends \PHPUnit_Framework_TestCase
{
private $app;
private $spy;
public function setUp()
{
$this->spy = new SpyOutput;
$this->app = new Application($this->spy);
}
public function testAppOutputsCorrectly()
{
$this->app->run();
$this->assertEquals('Hello, World!' . PHP_EOL, $this->spy->getMessage());
}
}
<?php
namespace ExampleApp\Tests;
use \ExampleApp\Progress;
use \SymfonyX\Component\Console\Output\SpyOutput;
class ProgressTest extends \PHPUnit_Framework_TestCase
{
public function test_progress_works_correctly()
{
$expected = <<< __EOF__
[ 0%] 0/100
[ 10%] 10/100
[ 20%] 20/100
[ 30%] 30/100
[ 40%] 40/100
[ 50%] 50/100
[ 60%] 60/100
[ 70%] 70/100
[ 80%] 80/100
[ 90%] 90/100
[100%] 100/100
__EOF__;
$spy = new SpyOutput;
$progress = new Progress(100, $spy);
for ($i = 0; $i < 100; $i++) {
$progress->setCurrentPosition($i);
}
$this->assertEquals($expected, $spy->getMessage());
}
}
<?php
namespace ExampleApp\Command;
use \ExampleApp\Progress;
use \Symfony\Component\Console\Command\Command,
\Symfony\Component\Console\Input\InputInterface,
\Symfony\Component\Console\Output\OutputInterface;
class ExecuteCommand extends Command
{
public function execute(InputInterface $input, OutputInterface $output)
{
$records = findRecords();
$progress = new Progress(count($records), $output);
foreach ($records as $i => $record) {
$progress->setCurrentPosition($i);
}
}
}
@XandrosRoberts
Copy link

Great, thanks!

@Bladebringer
Copy link

Bladebringer commented Jun 22, 2022

The issue of application safety is very relevant for me now. I really want to install a spy app on my wife's phone, I studied everything in detail on this source realspyapps.com/review/pctattletale/ and I think that there should be no problems with installation, but I'm very afraid that she will be able to notice the appearance of a spy on her phone. Anyone faced a similar situation? Do spy apps really work discreetly and safely?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment