silverstripe-testsession/tests/unit/TestSessionStubCodeWriterTest.php

53 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2016-08-29 06:17:53 +02:00
use SilverStripe\Dev\SapphireTest;
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);
}
}