Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- /* Testing
- /*
- /* Testing operators: <, >, ==, ===
- /* Testing type: object
- /*
- /* Expected behaviour:
- /* Based on [1] quote "Built-in classes can define its own comparison, different classes are uncomparable, same class - compare properties the same way as arrays (PHP 4), PHP 5 has its own explanation", the expected behaviour for < and > would be the same as for arrays pretty much.
- /* The expected behaviour for == and === are explained here [2], quote == -> "Two object instances are equal if they have the same attributes and values, and are instances of the same class." and === -> "object variables are identical if and only if they refer to the same instance of the same class.".
- /*
- /* Actual behaviour:
- /* The actual behaviour is as descired in the manual.
- /*
- /*
- /* Links:
- /* [1]: http://php.net/manual/en/language.operators.comparison.php
- /* [2]: http://php.net/manual/en/language.oop5.object-comparison.php#language.oop5.object-comparison
- /*
- */
- /**
- /*
- /* Testing operators: < and >
- /*
- */
- //Test case
- //Variations: amount, values and keys (order)
- //Test count: 10
- // Failed: 0
- // Passed: 10
- {
- //Test case 1.1
- $a = (object)["a" => 1];
- $b = (object)["a" => 1];
- //Passed
- var_dump("Same amount of elements, keys and values: " . "'<' -> " . bool2str($a < $b) . " '>' -> " . bool2str($a > $b));
- //Test case 1.2
- $a = (object)["a" => 1];
- $b = (object)["a" => 1, "b" => 1];
- //Passed
- var_dump("NOT same amount of elements, but same values: " . "'<' -> " . bool2str($a < $b) . " '>' -> " . bool2str($a > $b));
- //Test case 1.3
- $a = (object)["a" => 10];
- $b = (object)["a" => 1, "b" => 1];
- //Passed
- var_dump("NOT same amount of elements nor values: " . "'<' -> " . bool2str($a < $b) . " '>' -> " . bool2str($a > $b));
- //Test case 1.4
- $a = (object)["a" => 1];
- $b = (object)["b" => 1];
- //Passed
- var_dump("Same amount of element and values, NOT same keys: " . "'<' -> " . bool2str($a < $b) . " '>' -> " . bool2str($a > $b));
- //Test case 1.5
- $a = (object)["a" => 10];
- $b = (object)["a" => 1];
- //Passed
- var_dump("Same amount of elements and keys, NOT same values: " . "'<' -> " . bool2str($a < $b) . " '>' -> " . bool2str($a > $b));
- //Test case 1.6
- $a = (object)["a" => 1, "b" => 1];
- $b = (object)["b" => 1, "a" => 1];
- //Passed
- var_dump("Same amount of elements and keys in different order: " . "'<' -> " . bool2str($a < $b) . " '>' -> " . bool2str($a > $b));
- //Test case 1.7
- $a = (object)["a" => 1, "b" => 5];
- $b = (object)["b" => 5];
- //Passed
- var_dump("Same values, NOT same amount of elements nor keys: " . "'<' -> " . bool2str($a < $b) . " '>' -> " . bool2str($a > $b));
- //Test case 1.8
- $a = (object)["c" => 1];
- $b = (object)["a" => 10];
- //Passed
- var_dump("NOT same keys nor values: " . "'<' -> " . bool2str($a < $b) . " '>' -> " . bool2str($a > $b));
- //Test case 1.9
- $a = (object)["a" => 1, "b" => 1];
- $b = (object)["b" => 10, "a" => 1];
- //Passed
- var_dump("Same amount of elements and values, NOT same keys nor order: " . "'<' -> " . bool2str($a < $b) . " '>' -> " . bool2str($a > $b));
- //Test case 1.10
- class A {public $a = 1;}
- $a = new A;
- class B {public $a = 1;}
- $b = new B;
- //Passed
- var_dump("Same amount of elements and values and keys, but different not built-in class: " . "'<' -> " . bool2str($a < $b) . " '>' -> " . bool2str($a > $b));
- }
- echo PHP_EOL . PHP_EOL . PHP_EOL; //Test case separator
- /**
- /*
- /* Test case end
- /*
- */
- /**
- /*
- /* Testing operators: == and ===
- /*
- */
- //Test case
- //Variations: amount, values and keys (order)
- //Test count: 7
- // Failed: 0
- // Passed: 7
- {
- //Test case 2.1
- $a = (object)["a" => 1];
- $b = (object)["a" => 1];
- //Passed
- var_dump("Same amount of elements, values and keys: " . "'==' -> " . bool2str($a == $b) . " '===' -> " . bool2str($a === $b));
- //Test case 2.2
- $a = (object)["a" => 1];
- $b = (object)["a" => 10, "b" => 1];
- //Passed
- var_dump("NOT same amount of elements, but same values: " . "'==' -> " . bool2str($a == $b) . " '===' -> " . bool2str($a === $b));
- //Test case 2.3
- $a = (object)["a" => 10];
- $b = (object)["a" => 1];
- //Passed
- var_dump("Same amount of elements, but not values: " . "'==' -> " . bool2str($a == $b) . " '===' -> " . bool2str($a === $b));
- //Test case 2.4
- $a = (object)["a" => 1];
- $b = (object)["b" => 1];
- //Passed
- var_dump("Same amount of elements and values, but not keys: " . "'==' -> " . bool2str($a == $b) . " '===' -> " . bool2str($a === $b));
- //Test case 2.5
- $a = (object)["a" => 1, "b" => 2];
- $b = (object)["b" => 2, "a" => 1];
- //Passed
- var_dump("Same amount of elements, key and values, but different order: " . "'==' -> " . bool2str($a == $b) . " '===' -> " . bool2str($a === $b));
- //Test case 2.6
- class C {public $a = 1;}
- $a = new A;
- class D {public $a = 1;}
- $b = new B;
- //Passed
- var_dump("Same amount of elements and values and keys, but different not built-in class: " . "'==' -> " . bool2str($a == $b) . " '===' -> " . bool2str($a === $b));
- //Test case 2.7
- $a = (object)["a" => 1];
- $b = $a;
- //Passed
- var_dump("Same exact instance: " . "'==' -> " . bool2str($a == $b) . " '===' -> " . bool2str($a === $b));
- }
- echo PHP_EOL . PHP_EOL . PHP_EOL; //Test case separator
- /**
- /*
- /* Test case end
- /*
- */
- //NULL, TRUE, FALSE 2 str func
- function bool2str($v){if($v === NULL)return "NULL";elseif($v === FALSE)return "FALSE";elseif($v === TRUE)return "TRUE";else return "UNEXPECTED: '$v'";}
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement