php-forge/support

Support library tests for PHP

0.1.0 2024-01-21 10:27 UTC

This package is auto-updated.

Last update: 2024-11-21 14:53:27 UTC


README

Support.


PHPUnit Codecov Infection Psalm Psalm Coverage Style ci

Installation

The preferred way to install this extension is through composer.

Either run

composer require --prefer-dist php-forge/support

or add

"php-forge/support": "^0.1"

to the require-dev section of your composer.json file.

Usage

Equals without line ending

<?php

declare(strict_types=1);

namespace PHPForge\Support\Tests;

use PHPForge\Support\Assert;

Assert::equalsWithoutLE(
    <<<Text
    Foo
    Bar
    Text,
    "Foo\nBar"
);

Inaccessible property

<?php

declare(strict_types=1);

namespace PHPForge\Support\Tests;

use PHPForge\Support\Assert;

$object = new class () {
    private string $foo = 'bar';
};

$this->assertSame('bar', Assert::inaccessibleProperty($object, 'foo'));

Invoke method

<?php

declare(strict_types=1);

namespace PHPForge\Support\Tests;

use PHPForge\Support\Assert;

$object = new class () {
    protected function foo(): string
    {
        return 'foo';
    }
};

$this->assertSame('foo', Assert::invokeMethod($object, 'foo'));

Set inaccessible property

<?php

declare(strict_types=1);

namespace PHPForge\Support\Tests;

use PHPForge\Support\Assert;

$object = new class () {
    private string $foo = 'bar';
};

Assert::setInaccessibleProperty($object, 'foo', 'baz');

$this->assertSame('baz', Assert::inaccessibleProperty($object, 'foo'));

Remove files from directory

<?php

declare(strict_types=1);

namespace PHPForge\Support\Tests;

use PHPForge\Support\Assert;

$dir = __DIR__ . '/runtime';

mkdir($dir);
mkdir($dir . '/subdir');
touch($dir . '/test.txt');
touch($dir . '/subdir/test.txt');

Assert::removeFilesFromDirectory($dir);

$this->assertFileDoesNotExist($dir . '/test.txt');

rmdir(__DIR__ . '/runtime');

Support versions

PHP81 Yii30

Testing

Check the documentation testing to learn about testing.

Our social networks

Twitter

License

The MIT License. Please see License File for more information.