File: TestBase.php

package info (click to toggle)
matomo-component-decompress 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 444 kB
  • sloc: php: 3,125; makefile: 25; xml: 21
file content (54 lines) | stat: -rw-r--r-- 1,378 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
 */

namespace Tests\Matomo\Decompress;

use PHPUnit\Framework\TestCase;

abstract class TestBase extends TestCase
{
    protected $fixtureDirectory;
    protected $tempDirectory;

    protected function setUp(): void
    {
        parent::setUp();

        clearstatcache();

        $this->fixtureDirectory = __DIR__ . '/Fixture/';
        $this->tempDirectory = __DIR__ . '/tmp/';
    }

    protected function assertFileContentsEquals($expectedContent, $path)
    {
        $this->assertFileExists($path);

        $fd = fopen($path, 'rb');
        $actualContent = fread($fd, filesize($path));
        fclose($fd);

        $this->assertEquals($expectedContent, $actualContent);
    }

    /**
     * Asserts that a file does not exist.
     *
     * This function is for PHPUnit 8 compatibility
     * Remove it when PHPUnit 8 is removed and replace with assertFileDoesNotExist
     */
    public static function assertFileNotExists(string $filename, string $message = ''): void
    {
        if (!method_exists(parent::class, 'assertFileDoesNotExist')) {
            parent::assertFileNotExists($filename, $message);
            return;
        }

        parent::assertFileDoesNotExist($filename, $message);
    }
}