Commit 7c3a621a authored by Torsten Zühlsdorff's avatar Torsten Zühlsdorff
Browse files

Add assertNotSame() to allow check if values are not equal while ignoring the data type

parent 60cb64a1
Pipeline #211 passed with stages
in 9 seconds
1.7
===
- Feature: add assertSame()
- Feature: add assertNotSame()
1.6
===
......
......@@ -80,6 +80,7 @@ This is a full list of assertions which can be used:
- assertEquals($mixReal, $mixExpected, $strOptionalDescription = null)
- assertNotEquals($mixReal, $mixExpected, $strOptionalDescription = null)
- assertSame($mixReal, $mixExpected, $strOptionalDescription = null)
- assertNotSame($mixReal, $mixExpected, $strOptionalDescription = null)
- assertEmpty($mixValue, $strOptionalDescription = null)
- assertNull($mixValue, $strOptionalDescription = null)
- assertArrayHasKey($mixKey, $arrArray, $strOptionalDescription = null)
......
......@@ -36,6 +36,7 @@ require_once __DIR__ . '/inc/assertions/assertEquals.func.php';
require_once __DIR__ . '/inc/assertions/assertNotEquals.func.php';
require_once __DIR__ . '/inc/assertions/assertSame.func.php';
require_once __DIR__ . '/inc/assertions/assertNotSame.func.php';
require_once __DIR__ . '/inc/assertions/assertEmpty.func.php';
require_once __DIR__ . '/inc/assertions/assertNull.func.php';
......
......@@ -9,7 +9,7 @@ namespace APHPUnit\Testcases;
* @param $boolForceReturn - force return of assertion state
*
* test if the given value do NOT matches the
* expected value
* expected value. comparission is type-safe
*
* set $strDescription for additional output in case of error
*
......
<?php
namespace APHPUnit\Testcases;
/**
* @param $mixReal - the value to test against the expectation
* @param $mixExpected - the expected value
* @param $strDescription - optional description of error-case
* @param $boolForceReturn - force return of assertion state
*
* test if the given value do NOT matches the
* expected value. data type is ignored for test.
*
* set $strDescription for additional output in case of error
*
* create the assertion-environment and send
* the result of the test to the queue
*
* if $boolForceReturn is true, do NOT send the result
* to the queue, but return it.
*
**/
function assertNotSame($mixReal, $mixExpected,
string $strDescription = null,
bool $boolForceReturn = false) {
$arrEnv = getAssertionEnvironment();
$arrEnv['success'] = ($mixReal != $mixExpected) ? true : false;
$arrEnv['result_real'] = var_export($mixReal, true);
$arrEnv['result_expected'] = var_export($mixExpected, true);
if(!is_null($strDescription) && false === $arrEnv['success'])
$arrEnv['description'] = $strDescription;
if(true === $boolForceReturn)
return $arrEnv;
$objQueue = new \SimpleIPC(QUEUE_IDENTIFIER);
$objQueue->send(serialize($arrEnv));
}
<?php
namespace APHPUnit\Testcases;
/**
* expect true since values are not equal
**/
function testAssertNotSameTrue() {
$strReal = 'muff';
$strExpected = 'foo';
$arrResult = assertNotSame($strReal, $strExpected, null, true);
assertTrue($arrResult['success']);
}
/**
* expect true since values are not equal
**/
function testAssertNotSameAndDifferentTypeTrue() {
$strReal = 123;
$strExpected = '124';
$arrResult = assertNotSame($strReal, $strExpected, null, true);
assertTrue($arrResult['success']);
}
/**
* expect false since description should only be set in error-case
**/
function testAssertNotSameTrueIgnoresDescription() {
$strReal = 'muff';
$strExpected = 'foo';
$strDescription = 'error-message';
$arrResult = assertNotSame($strReal, $strExpected, $strDescription, true);
assertFalse(array_key_exists('description', $arrResult));
}
/**
* expect false since values are equal
**/
function testAssertNotSameFalse() {
$strReal = 'muff';
$strExpected = 'muff';
$arrResult = assertNotSame($strReal, $strExpected, null, true);
assertFalse($arrResult['success']);
}
/**
* expect description to be set since the assertion fails
**/
function testAssertNotSameFalseWithDescription() {
$strReal = 'muff';
$strExpected = 'muff';
$strDescription = 'error-message';
$arrResult = assertNotSame($strReal, $strExpected, $strDescription, true);
assertTrue(array_key_exists('description', $arrResult));
assertSame($arrResult['description'], $strDescription);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment