Skip to content

Commit

Permalink
test: Call PHPUnit assertions statically
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondrej Vana committed Oct 21, 2015
1 parent 2b9285d commit 9542889
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 66 deletions.
32 changes: 16 additions & 16 deletions tests/Keboola/Json/AnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testAnalyze()
$analyzer = new Analyzer($this->getLogger('analyzer', true));
$analyzer->analyze($data, 'root');

$this->assertEquals(
self::assertEquals(
[
'root.arr' => ['data' => 'scalar'],
'root.obj' => [
Expand Down Expand Up @@ -75,7 +75,7 @@ public function testAnalyzeStrict()
$analyzer->setStrict(true);
$analyzer->analyze($data, 'root');

$this->assertEquals(
self::assertEquals(
[
'root.arr' => ['data' => 'integer'],
'root.obj' => [
Expand Down Expand Up @@ -110,7 +110,7 @@ public function testAnalyzeStrictError()
$analyzer->setStrict(true);
$analyzer->analyze($data, 'root');

$this->assertEquals(
self::assertEquals(
[
'root.arr' => ['data' => 'integer'],
'root.obj' => [
Expand Down Expand Up @@ -150,7 +150,7 @@ public function testAnalyzeAutoArrays()
$analyzer->getStruct()->setAutoUpgradeToArray(true);
$analyzer->analyze($data, 'root');

$this->assertEquals(
self::assertEquals(
[
'root.arrOfObjects' => ['innerId' => 'scalar'],
'root.arr' => ['data' => 'scalar'],
Expand Down Expand Up @@ -230,20 +230,20 @@ public function testIsAnalyzed()
];

$analyzer->analyze($data, 'test');
$this->assertFalse($analyzer->isAnalyzed('test'));
self::assertFalse($analyzer->isAnalyzed('test'));

$analyzer = new Analyzer($this->getLogger('analyzer', true), null, 1);
$this->assertFalse($analyzer->isAnalyzed('test'));
self::assertFalse($analyzer->isAnalyzed('test'));
$analyzer->analyze($data, 'test');
$this->assertTrue($analyzer->isAnalyzed('test'));
self::assertTrue($analyzer->isAnalyzed('test'));
}

public function testAnalyzeRow()
{
$analyzer = new Analyzer($this->getLogger('analyzer', true));

$this->callMethod($analyzer, 'analyzeRow', [new \stdClass, 'empty']);
$this->assertEquals(['empty' => []], $analyzer->getStruct()->getStruct());
self::assertEquals(['empty' => []], $analyzer->getStruct()->getStruct());

$this->callMethod($analyzer, 'analyzeRow', [(object) [
'k' => 'v',
Expand All @@ -252,7 +252,7 @@ public function testAnalyzeRow()
]
], 'test']);

$this->assertEquals(
self::assertEquals(
[
'empty' => [],
'test.field' => [
Expand Down Expand Up @@ -289,7 +289,7 @@ public function testAnalyzeKnownArray()
$analyzer->analyze($data1, 'test');
$analyzer->analyze($data2, 'test');

$this->assertEquals(
self::assertEquals(
[
'test.arr' => ['data' => 'scalar'],
'test' => [
Expand Down Expand Up @@ -329,7 +329,7 @@ public function testAnalyzeKnownArrayMismatch()
$analyzer->analyze($data1, 'test');
$analyzer->analyze($data2, 'test');

$this->assertEquals(
self::assertEquals(
[
'test.arr' => ['data' => 'scalar'],
'test' => [
Expand Down Expand Up @@ -371,7 +371,7 @@ public function testAnalyzeKnownArrayMismatch2()
$analyzer->analyze($data1, 'test');
$analyzer->analyze($data2, 'test');

$this->assertEquals(
self::assertEquals(
[
'test.arr' => ['data' => 'scalar'],
'test' => [
Expand Down Expand Up @@ -409,7 +409,7 @@ public function testAnalyzeKnownArrayMismatch3()
$analyzer->analyze($data1, 'test');
$analyzer->analyze($data2, 'test');

$this->assertEquals(
self::assertEquals(
[
'test.arr' => ['data' => 'scalar'],
'test' => [
Expand Down Expand Up @@ -440,7 +440,7 @@ public function testAnalyzeEmptyArrayOfObject()

$analyzer->analyze($data, 'test');

$this->assertEquals(
self::assertEquals(
[
'test' => [
'id' => 'scalar',
Expand Down Expand Up @@ -483,7 +483,7 @@ public function testAnalyzeEmptyArrayOfObjectAutoUpgrade()

$analyzer->analyze($data, 'test');

$this->assertEquals(
self::assertEquals(
[
'test' => [
'id' => 'scalar',
Expand Down Expand Up @@ -530,7 +530,7 @@ public function testArrayOfNull()
'null2s'
);

$this->assertEquals(
self::assertEquals(
[
's2null' => [
'val' => 'arrayOfscalar',
Expand Down
48 changes: 24 additions & 24 deletions tests/Keboola/Json/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testZeroValues()

$parser->process($json, 'entities');
// yo dawg
$this->assertEquals(
self::assertEquals(
"0",
str_getcsv(
file(
Expand Down Expand Up @@ -78,7 +78,7 @@ public function testParentIdPrimaryKey()
$parser->addPrimaryKeys(['test' => "pk"]);
$parser->process($data, 'test');
foreach($parser->getCsvFiles() as $type => $file) {
$this->assertEquals(
self::assertEquals(
file_get_contents($this->getDataDir() . "PrimaryKeyTest/{$type}.csv"),
file_get_contents($file->getPathname())
);
Expand All @@ -97,7 +97,7 @@ public function testParentIdPrimaryKeyMultiLevel()
]);
$parser->process($data, 'outer');
foreach($parser->getCsvFiles() as $type => $file) {
$this->assertEquals(
self::assertEquals(
file_get_contents($this->getDataDir() . "PrimaryKeyTest/{$type}.csv"),
file_get_contents($file->getPathname())
);
Expand All @@ -121,7 +121,7 @@ public function testParentIdHash()

$parser->process($data, 'hash');
foreach($parser->getCsvFiles() as $type => $file) {
$this->assertEquals(
self::assertEquals(
file_get_contents($this->getDataDir() . "PrimaryKeyTest/{$type}.csv"),
file_get_contents($file->getPathname())
);
Expand Down Expand Up @@ -185,7 +185,7 @@ public function testParentIdHashSameValues()
}

foreach($parser->getCsvFiles() as $type => $file) {
$this->assertEquals(
self::assertEquals(
file_get_contents($this->getDataDir() . "{$type}.csv"),
file_get_contents($file->getPathname())
);
Expand Down Expand Up @@ -250,7 +250,7 @@ public function testParentIdHashSameValuesDeepNesting()
$parser->process($data, 'nested_hash_deep');

foreach($parser->getCsvFiles() as $type => $file) {
$this->assertEquals(
self::assertEquals(
file_get_contents($this->getDataDir() . "{$type}.csv"),
file_get_contents($file->getPathname())
);
Expand Down Expand Up @@ -295,7 +295,7 @@ protected function timeDiffCompare($parser)
foreach(['hash' => 'later', 'hash_arr' => 'later_arr'] as $file => $later) {
$old = file($files[$file]->getPathname());
$new = file($files[$later]->getPathname());
$this->assertNotEquals(
self::assertNotEquals(
$old,
$new
);
Expand All @@ -307,8 +307,8 @@ protected function timeDiffCompare($parser)
foreach($old as $key => $row) {
$oldRow = str_getcsv($row);
$newRow = str_getcsv($new[$key]);
$this->assertEquals($oldRow[0], $newRow[0]);
$this->assertNotEquals($oldRow[1], $newRow[1]);
self::assertEquals($oldRow[0], $newRow[0]);
self::assertNotEquals($oldRow[1], $newRow[1]);
}
}
}
Expand All @@ -324,7 +324,7 @@ public function testNoStrictScalarChange()
]');

$parser->process($data, 'threepack');
$this->assertEquals(
self::assertEquals(
[
'"field"' . PHP_EOL,
'"128"' . PHP_EOL,
Expand Down Expand Up @@ -382,7 +382,7 @@ public function testArrayParentId()
'first_parent' => 1,
'second_parent' => "two"]
);
$this->assertEquals(
self::assertEquals(
file_get_contents($this->getDataDir() . 'ParentIdsTest.csv'),
file_get_contents($parser->getCsvFiles()['test'])
);
Expand All @@ -392,7 +392,7 @@ public function testProcessSimpleArray()
{
$parser = $this->getParser();
$parser->process(json_decode('["a","b"]'));
$this->assertEquals(
self::assertEquals(
[
'"data"' . PHP_EOL,
'"a"' . PHP_EOL,
Expand All @@ -412,8 +412,8 @@ public function testInputDataIntegrity()
$parser->process($inputData);
$parser->getCsvFiles();

$this->assertEquals($originalData, $inputData);
$this->assertEquals(serialize($originalData), serialize($inputData), "The object does not match original.");
self::assertEquals($originalData, $inputData);
self::assertEquals(serialize($originalData), serialize($inputData), "The object does not match original.");
}

/**
Expand Down Expand Up @@ -447,12 +447,12 @@ public function testNestedArrays()
];

$parser->process($data);
$this->assertEquals(
self::assertEquals(
true,
$logHandler->hasWarning("Unsupported array nesting in 'root'! Converting to JSON string."),
"Warning should have been logged"
);
$this->assertEquals(
self::assertEquals(
file_get_contents($this->getDataDir() . 'NestedArraysJson.csv'),
file_get_contents($parser->getCsvFiles()['root'])
);
Expand All @@ -478,7 +478,7 @@ public function testHeaderSpecialChars()

$parser->process($data);

$this->assertEquals(
self::assertEquals(
'"id","KeywordRanking_attributes_date","KeywordRanking_stuff_I_ARE_POTAT","KeywordRanking_stuff_kek_ser_ou_ly"' . PHP_EOL .
'"123456","2015-03-20","aaa$@!","now"' . PHP_EOL,
file_get_contents($parser->getCsvFiles()['root'])
Expand Down Expand Up @@ -564,15 +564,15 @@ public function testAutoUpgradeToArray()
$parser->process($data);

// TODO guess this could be in files..
$this->assertEquals(
self::assertEquals(
'"key"' . PHP_EOL .
'"root_eae48f50d1159c41f633f876d6c66411"' . PHP_EOL .
'"root_83cb9491934903381f6808ac79842022"' . PHP_EOL .
'"root_6d231f9592a4e259452229e2be31f42e"' . PHP_EOL,
file_get_contents($parser->getCsvFiles()['root'])
);

$this->assertEquals(
self::assertEquals(
'"subKey1","subKey2","JSON_parentId"' . PHP_EOL .
'"val1.1","val1.2","root_eae48f50d1159c41f633f876d6c66411"' . PHP_EOL .
'"val2.1.1","val2.1.2","root_83cb9491934903381f6808ac79842022"' . PHP_EOL .
Expand Down Expand Up @@ -605,14 +605,14 @@ public function testAutoUpgradeToArray()

$parser->process($data2, 'arr');

$this->assertEquals(
self::assertEquals(
'"key"' . PHP_EOL .
'"arr_d03523e758a12366bd7062ee727c4939"' . PHP_EOL .
'"arr_6d231f9592a4e259452229e2be31f42e"' . PHP_EOL,
file_get_contents($parser->getCsvFiles()['arr'])
);

$this->assertEquals(
self::assertEquals(
'"subKey1","subKey2","JSON_parentId"' . PHP_EOL .
'"val2.1.1","val2.1.2","arr_d03523e758a12366bd7062ee727c4939"' . PHP_EOL .
'"val2.2.1","val2.2.2","arr_d03523e758a12366bd7062ee727c4939"' . PHP_EOL .
Expand Down Expand Up @@ -715,15 +715,15 @@ public function testAutoUpgradeToArrayString()

$parser->process($data);

$this->assertEquals(
self::assertEquals(
'"key"' . PHP_EOL .
'"root_0c616a2609bd2e8d88574f3f856170c5"' . PHP_EOL .
'"root_3cc17a87c69e64707ac357e84e5a9eb8"' . PHP_EOL .
'"root_af523454cc66582ad5dcec3f171b35ed"' . PHP_EOL,
file_get_contents($parser->getCsvFiles()['root'])
);

$this->assertEquals(
self::assertEquals(
'"data","JSON_parentId"' . PHP_EOL .
'"str1","root_0c616a2609bd2e8d88574f3f856170c5"' . PHP_EOL .
'"str2.1","root_3cc17a87c69e64707ac357e84e5a9eb8"' . PHP_EOL .
Expand All @@ -746,7 +746,7 @@ public function testIncompleteData()

$parser->process([(object) ['id' => 1]]);

$this->assertEquals(
self::assertEquals(
'"id","value"' . PHP_EOL .
'"1",""' . PHP_EOL,
file_get_contents($parser->getCsvFiles()['root'])
Expand Down
Loading

0 comments on commit 9542889

Please sign in to comment.