mirror of
https://github.com/silverstripe/silverstripe-testsession
synced 2024-10-22 14:06:00 +02:00
56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\TestSession\Tests;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
use SilverStripe\TestSession\TestSessionStubCodeWriter;
|
|
|
|
class TestSessionStubCodeWriterTest extends SapphireTest
|
|
{
|
|
|
|
public function tearDown()
|
|
{
|
|
parent::tearDown();
|
|
|
|
$file = TEMP_FOLDER . '/TestSessionStubCodeWriterTest-file.php';
|
|
if (file_exists($file)) {
|
|
unlink($file);
|
|
}
|
|
}
|
|
|
|
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"
|
|
);
|
|
}
|
|
|
|
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"
|
|
);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|