diff --git a/composer.json b/composer.json index 97c02a2..5a6dc8e 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,9 @@ "CobaltGrid\\AIRACCalculator\\": "src/" } }, + "scripts": { + "test": "phpunit" + }, "require-dev": { "phpunit/phpunit": "^8.2|^9.0", "symfony/dom-crawler": "^4.3", diff --git a/tests/AccuracyTest.php b/tests/AccuracyTest.php index 3acc0c8..4ab1cff 100644 --- a/tests/AccuracyTest.php +++ b/tests/AccuracyTest.php @@ -12,7 +12,7 @@ public function testItIsTheSameAsOfficalSource(): void $years = $crawler->filter('table table'); // Check that it finds 3/4/5 years as expected - $this->assertContains(count($years), [3, 4, 5]); + $this->assertContains(count($years), [3, 4, 5, 6]); foreach ($years as $year) { $year = new Crawler($year); @@ -24,8 +24,12 @@ public function testItIsTheSameAsOfficalSource(): void $cycle = $cycles->eq($i); $cycleNumber = $cycle->filter('td:nth-of-type(2)')->text(); - $cycleDate = new DateTime($cycle->filter('td:nth-of-type(5)')->text(), new DateTimeZone('UTC')); - $this->assertEquals($cycleDate, AIRACCycle::fromCycleCode($cycleNumber)->getEffectiveDate()); + $cycleDateRaw = $cycle->filter('td:nth-of-type(5)')->text(); + + preg_match("/\d{2} [A-Z]{3} \d{2,4}/", $cycleDateRaw, $matches); + + $cycleDate = new DateTime($matches[0], new DateTimeZone('UTC')); + $this->assertEquals($cycleDate, AIRACCycle::fromCycleCode($cycleNumber)->getEffectiveDate(), "Cycle $cycleNumber does not match official source."); } } }