2013-11-27 19:29:44 +01:00
|
|
|
<?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
|
|
|
|
{
|
2013-11-27 19:29:44 +01:00
|
|
|
|
2015-12-17 19:17:16 +01:00
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
2013-11-27 19:29:44 +01:00
|
|
|
|
2015-12-17 19:17:16 +01:00
|
|
|
$file = TEMP_FOLDER . '/TestSessionStubCodeWriterTest-file.php';
|
|
|
|
if (file_exists($file)) {
|
|
|
|
unlink($file);
|
|
|
|
}
|
|
|
|
}
|
2013-11-27 19:29:44 +01:00
|
|
|
|
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"
|
|
|
|
);
|
|
|
|
}
|
2013-11-27 19:29:44 +01:00
|
|
|
|
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"
|
|
|
|
);
|
|
|
|
}
|
2013-11-27 19:29:44 +01:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|