<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
antonioprimera / phpunit-custom-assertions example snippets
namespace AntonioPrimera\Testing\Tests\Unit;
use AntonioPrimera\Testing\CustomAssertions;
use PHPUnit\Framework\TestCase;
class FileAssertionsTest extends TestCase
{
use CustomAssertions;
/** @test */
public function it_can_do_any_of_the_implemented_assertions()
{
//you can call any of the assertions as instance methods, functions or static methods
$this->assertFileContains('CustomAssertions', __FILE__);
assertFileContains(['namespace', 'use'], __FILE__);
static::assertFileContentsEquals('abc', __FILE__, function($str) { return 'abc'; });
//compares two lists
$this->assertListsEqual(['a', 1, [true, null, collect([0, 5])]], [[null, true, [5,0]], 1,'a']);
//the following assertion is expected to fail, containing the messages given as parameters
$this->expectAssertionToFail(__FILE__ . '.js');
$this->assertFilesExist([__FILE__, __FILE__ . '.js']);
}
}
$this->assertListsEqual(['a', 1, [true, null, collect([0, 5])]], [[null, true, [5, 0]], 1, 'a']);
//this will succeed in non-strict mode, but will fail in strict mode
$this->assertListsEqual(['a', 1, [1, null, collect([0, 5])]], [[null, true, [5, false]], 1, 'a']);
public function test_that_something_does_not_work()
{
//successful assertion
$this->assertFoldersExist([__DIR__, app_path(), resource_path()]);
//expect the next assertion to fail and the failure message to contain the 2 missing folder paths
$this->expectAssertionToFail(app_path('random/folder'), resource_path('nix/da'));
//failing assertion
$this->assertFoldersExist([__DIR__, app_path('random/folder'), resource_path('nix/da')]);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.