Skip to content

Instantly share code, notes, and snippets.

@geshan
Created January 2, 2021 11:06
Show Gist options
  • Save geshan/75153b39e6277dd8ece4048cf1d44ae5 to your computer and use it in GitHub Desktop.
Save geshan/75153b39e6277dd8ece4048cf1d44ae5 to your computer and use it in GitHub Desktop.
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
class AssertionsTest extends TestCase
{
public function testAssertJsonStringEqualsJsonString()
{
$this->assertJsonStringEqualsJsonString('{"message": "ok"}', json_encode(["message" => "ok"]), 'Check message ok json');
}
public function testRegex()
{
$this->assertRegExp('/Exception 40\d/', 'Exception 501', 'Check if it is exception 40x');
}
public function testAssertStringContainsString()
{
$this->assertStringContainsString('Error', 'Error id is reqired, quote is required', 'Check if word Error is present');
}
public function testAssetEqualsWithDelta()
{
$this->assertEqualsWithDelta(34.3, 34.1, 0.5, '0.5 degree variance in temprature is allwoed');
}
public function testAssertArrayHasKey()
{
$exchangeRates = ['usd' => 0.77, 'euro' => 0.63];
$this->assertArrayHasKey('usd', $exchangeRates, 'Check if USD is available');
$this->assertEquals(0.77, $exchangeRates['usd'], 'Test if USD rate is 0.77');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment