1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-06-12 17:11:00 +02:00
Files
php-debugbar/tests/DebugBar/Tests/Storage/FileStorageTest.php
Stefan Schramm dff80cdb1c Fix PHP 8.2 deprecations (#531)
* Fix deprecation: Use of "parent" in callables is deprecated

* Fix deprecations in tests

Creation of dynamic properties is deprecated since php 8.2
2023-08-18 19:36:53 +02:00

72 lines
1.9 KiB
PHP

<?php
namespace DebugBar\Tests\Storage;
use DebugBar\Tests\DebugBarTestCase;
use DebugBar\Storage\FileStorage;
class FileStorageTest extends DebugBarTestCase
{
private $dirname;
private $s;
private $data;
public function setUp(): void
{
$this->dirname = tempnam(sys_get_temp_dir(), 'debugbar');
if (file_exists($this->dirname)) {
unlink($this->dirname);
}
mkdir($this->dirname, 0777);
$this->s = new FileStorage($this->dirname);
$this->data = array('__meta' => array('id' => 'foo'));
$this->s->save('bar', $this->data);
}
public function teardown(): void
{
$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($this->dirname, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($files as $fileinfo) {
$todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
$todo($fileinfo->getRealPath());
}
rmdir($this->dirname);
}
public function testSave()
{
$this->s->save('foo', $this->data);
$this->assertFileExists($this->dirname . '/foo.json');
$this->assertJsonStringEqualsJsonFile($this->dirname . '/foo.json', json_encode($this->data));
}
public function testGet()
{
$data = $this->s->get('bar');
$this->assertEquals($this->data, $data);
}
public function testFind()
{
$results = $this->s->find();
$this->assertContains($this->data['__meta'], $results);
}
public function testClear()
{
$this->s->clear();
// avoid depreciation message on newer PHPUnit versions. Can be removed after
if (method_exists($this, 'assertFileDoesNotExist')) {
$this->assertFileDoesNotExist($this->dirname . '/foo.json');
} else {
$this->assertFileNotExists($this->dirname . '/foo.json');
}
}
}