Skip to content

Instantly share code, notes, and snippets.

@guiled
Last active March 13, 2017 09:41
Show Gist options
  • Save guiled/2a23a91b57f3438371afb2f1a2c2f116 to your computer and use it in GitHub Desktop.
Save guiled/2a23a91b57f3438371afb2f1a2c2f116 to your computer and use it in GitHub Desktop.
Test write to a file
<?php
namespace Project\Log\tests\units;
use \mageekguy\atoum;
class Logger extends atoum\test
{
public function testStdout()
{
$this
->assert('Log to default : output')
->given($this->newTestedInstance)
->and($str = 'test output to default')
->output(function () use ($str){
$this->testedInstance->log($str);
})->contains($str)
->assert('Log to specified output : php://output (like default?)')
->given($this->newTestedInstance('php://output'))
->and($str = 'test output to stdout')
->output(function () use ($str){
$this->testedInstance->log($str);
})->contains($str)
->assert('Log to a specified file')
->given(
$str = 'test XXX output to a file',
$file = \atoum\mock\streams\fs\file::get('testlog'),
$this->newTestedInstance($file->getPath())
)
->if($this->testedInstance->log($str))
->stream($file)->isWritten()
->string(file_get_contents($file->getPath()))
->contains($str)
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment