diff --git a/tests/FormatterTest.php b/tests/FormatterTest.php new file mode 100644 index 0000000..66f0516 --- /dev/null +++ b/tests/FormatterTest.php @@ -0,0 +1,48 @@ + $value) { + $stdClass->{$key} = $value; + } + return $stdClass; + } + + /** + * @param $input + * @param $comparator + * @param $expected + * @dataProvider sortDataProvider + */ + public function testSort($input, $comparator, $expected) + { + $actual = Formatter::sort($input, $comparator); + $this->assertEquals($expected, $actual); + $actualKeyMap = (array_keys((array)$actual)); + $expectedKeyMap = (array_keys((array)$expected)); + $this->assertEquals($expectedKeyMap, $actualKeyMap); + } + + public function sortDataProvider() + { + return [ + [self::stdClass(["b" => 1, "a" => 2, "c" => "c"]), "strcmp", self::stdClass(["a" => 2, "b" => 1, "c" => "c"])], + [1, "strcmp", 1], + [[1, 3, 2], "strcmp", [1, 3, 2]] + ]; + } +}