silverstripe-testsession/tests/TestSessionStubCodeWriterTe...

56 lines
1.6 KiB
PHP
Raw Normal View History

<?php
2016-08-29 06:17:53 +02:00
2017-04-21 01:58:27 +02:00
namespace SilverStripe\TestSession\Tests;
2016-08-29 06:17:53 +02:00
use SilverStripe\Dev\SapphireTest;
2017-04-21 01:58:27 +02:00
use SilverStripe\TestSession\TestSessionStubCodeWriter;
2016-08-29 06:17:53 +02:00
2015-12-17 19:17:16 +01:00
class TestSessionStubCodeWriterTest extends SapphireTest
{
2015-12-17 19:17:16 +01:00
public function tearDown()
{
parent::tearDown();
2015-12-17 19:17:16 +01:00
$file = TEMP_FOLDER . '/TestSessionStubCodeWriterTest-file.php';
if (file_exists($file)) {
unlink($file);
}
}
2015-12-17 19:17:16 +01:00
public function testWritesHeaderOnNewFile()
{
$file = TEMP_FOLDER . '/TestSessionStubCodeWriterTest-file.php';
$writer = new TestSessionStubCodeWriter($file);
$writer->write('foo();', false);
$this->assertFileExists($file);
$this->assertEquals(
file_get_contents($writer->getFilePath()),
"<?php\nfoo();\n"
);
}
2015-12-17 19:17:16 +01:00
public function testWritesWithAppendOnExistingFile()
{
$file = TEMP_FOLDER . '/TestSessionStubCodeWriterTest-file.php';
$writer = new TestSessionStubCodeWriter($file);
$writer->write('foo();', false);
$writer->write('bar();', false);
$this->assertFileExists($file);
$this->assertEquals(
file_get_contents($writer->getFilePath()),
"<?php\nfoo();\nbar();\n"
);
}
2015-12-17 19:17:16 +01:00
public function testReset()
{
$file = TEMP_FOLDER . '/TestSessionStubCodeWriterTest-file.php';
$writer = new TestSessionStubCodeWriter($file);
$writer->write('foo();', false);
$this->assertFileExists($file);
$writer->reset();
$this->assertFileNotExists($file);
}
}