From 7e13dd4ae8b51fd8db9aec11be7c8675e518fd6a Mon Sep 17 00:00:00 2001 From: Seth Sharp Date: Sat, 5 Oct 2024 09:33:21 +1000 Subject: [PATCH 1/4] wip --- composer.json | 11 ++++++--- tests/Feature/ExampleTest.php | 5 ++++ tests/Pest.php | 45 +++++++++++++++++++++++++++++++++++ tests/TestCase.php | 13 ---------- tests/Unit/ExampleTest.php | 5 ++++ 5 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 tests/Feature/ExampleTest.php create mode 100644 tests/Pest.php delete mode 100644 tests/TestCase.php create mode 100644 tests/Unit/ExampleTest.php diff --git a/composer.json b/composer.json index b4c0736..34de193 100644 --- a/composer.json +++ b/composer.json @@ -20,14 +20,19 @@ "guzzlehttp/guzzle": "^7.8", "nesbot/carbon": "^3.7" }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, "extra": { "laravel":{ "providers": [ "SethSharp\\OddsApi\\OddsApiServiceProvider" ] } + }, + "require-dev": { + "pestphp/pest": "^3.2" + }, + "config": { + "allow-plugins": { + "pestphp/pest-plugin": true + } } } diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php new file mode 100644 index 0000000..61cd84c --- /dev/null +++ b/tests/Feature/ExampleTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..fd279ad --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,45 @@ +extend(Tests\TestCase::class)->in('Feature'); + +/* +|-------------------------------------------------------------------------- +| Expectations +|-------------------------------------------------------------------------- +| +| When you're writing tests, you often need to check that values meet certain conditions. The +| "expect()" function gives you access to a set of "expectations" methods that you can use +| to assert different things. Of course, you may extend the Expectation API at any time. +| +*/ + +expect()->extend('toBeOne', function () { + return $this->toBe(1); +}); + +/* +|-------------------------------------------------------------------------- +| Functions +|-------------------------------------------------------------------------- +| +| While Pest is very powerful out-of-the-box, you may have some testing code specific to your +| project that you don't want to repeat in every file. Here you can also expose helpers as +| global functions to help you to reduce the number of lines of code in your test files. +| +*/ + +function something() +{ + // .. +} diff --git a/tests/TestCase.php b/tests/TestCase.php deleted file mode 100644 index f257667..0000000 --- a/tests/TestCase.php +++ /dev/null @@ -1,13 +0,0 @@ -markTestSkipped(); - } -} \ No newline at end of file diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php new file mode 100644 index 0000000..61cd84c --- /dev/null +++ b/tests/Unit/ExampleTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); From 27661ebd9eb938bad11c2485a217c6ebf01bd040 Mon Sep 17 00:00:00 2001 From: Seth Sharp Date: Sat, 5 Oct 2024 09:37:53 +1000 Subject: [PATCH 2/4] update action --- .github/workflows/testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index a9a478d..5e10e49 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -26,5 +26,5 @@ jobs: - name: Install composer dependencies run: composer install --no-cache --no-ansi --no-interaction --no-progress - - name: Execute tests - run: ./vendor/bin/phpunit \ No newline at end of file + - name: Execute pest tests + run: ./vendor/bin/pest From 4cf59e4d77e8c07bfb89289ce5c64060803f38e4 Mon Sep 17 00:00:00 2001 From: Seth Sharp Date: Sat, 5 Oct 2024 11:29:14 +1000 Subject: [PATCH 3/4] benchmark testing --- composer.json | 6 ++- tests/Feature/ExampleTest.php | 5 --- tests/Unit/ExampleTest.php | 5 --- tests/Unit/OddsClientTest.php | 80 +++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 11 deletions(-) delete mode 100644 tests/Feature/ExampleTest.php delete mode 100644 tests/Unit/ExampleTest.php create mode 100644 tests/Unit/OddsClientTest.php diff --git a/composer.json b/composer.json index 25f592f..dd38423 100644 --- a/composer.json +++ b/composer.json @@ -29,11 +29,15 @@ } }, "require-dev": { - "pestphp/pest": "^3.2" + "pestphp/pest": "^3.2", + "orchestra/testbench": "^9.5" }, "config": { "allow-plugins": { "pestphp/pest-plugin": true } + }, + "scripts": { + "test": "pest" } } diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index 61cd84c..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,5 +0,0 @@ -toBeTrue(); -}); diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index 61cd84c..0000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,5 +0,0 @@ -toBeTrue(); -}); diff --git a/tests/Unit/OddsClientTest.php b/tests/Unit/OddsClientTest.php new file mode 100644 index 0000000..f149661 --- /dev/null +++ b/tests/Unit/OddsClientTest.php @@ -0,0 +1,80 @@ +app['config']->set('odds-api.default_region', 'au'); + $this->app['config']->set('odds-api.default_odds_format', 'decimal'); + } + + public function testSetsUpProvidedApiKeyAndDefaultParams() + { + $apiKey = 'test-api-key'; + $oddsClient = new OddsClient($apiKey); + + $this->assertEquals('https://api.the-odds-api.com', $oddsClient->getApiEndpoint()); + + $this->assertEquals([ + 'api_key' => $apiKey, + 'regions' => 'au', + 'oddsFormat' => 'decimal', + ], $oddsClient->getParams()); + } + + public function testSetsProvidedApiEndpoint() + { + $oddsClient = new OddsClient('test-api-key', 'a-new-endpoint'); + + $this->assertEquals('a-new-endpoint', $oddsClient->getApiEndpoint()); + } + + public function testSetsRegionString() + { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->setRegion('us'); + + $this->assertEquals('us', $oddsClient->getParams()['regions']); + } + + public function testSetsMarkets() + { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->setMarkets([ + 'h2h', + 'spreads', + 'outrights' + ]); + + $this->assertEquals('0=h2h,1=spreads,2=outrights', $oddsClient->getParams()['markets']); + } + + public function testSetsBookmakers() + { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->setBookmakers([ + 'sportsbet', + 'tab', + 'topsport' + ]); + + $this->assertEquals('0=sportsbet,1=tab,2=topsport', $oddsClient->getParams()['bookmakers']); + } +} From 7454a988f2c757c545ff791597031727cbcda535 Mon Sep 17 00:00:00 2001 From: Seth Sharp Date: Sat, 5 Oct 2024 11:42:53 +1000 Subject: [PATCH 4/4] tests --- src/OddsClient.php | 4 +- tests/Unit/OddsClientTest.php | 94 +++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src/OddsClient.php b/src/OddsClient.php index 5b67594..bb997a5 100644 --- a/src/OddsClient.php +++ b/src/OddsClient.php @@ -159,10 +159,10 @@ public function setBookmakers(mixed $bookmakers): self } /** - * @param string|array $eventId + * @param mixed $eventId * @return $this */ - public function setEvents(string|array $eventId): self + public function setEvents(mixed $eventId): self { if (is_array($eventId)) { $this->params['eventIds'] = $this->buildEvents($eventId); diff --git a/tests/Unit/OddsClientTest.php b/tests/Unit/OddsClientTest.php index f149661..ca2dcca 100644 --- a/tests/Unit/OddsClientTest.php +++ b/tests/Unit/OddsClientTest.php @@ -77,4 +77,98 @@ public function testSetsBookmakers() $this->assertEquals('0=sportsbet,1=tab,2=topsport', $oddsClient->getParams()['bookmakers']); } + + public function testSetsEventsString() + { + + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->setEvents('some-event'); + + $this->assertEquals('some-event', $oddsClient->getParams()['eventIds']); + } + + public function testSetsEventsArray() + { + + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->setEvents([ + 'event-1', + 'event-2', + 'event-3', + ]); + + $this->assertEquals('event-1,event-2,event-3', $oddsClient->getParams()['eventIds']); + } + + public function testSetsOddsFormat() + { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->oddsFormat('american'); + + $this->assertEquals('american', $oddsClient->getParams()['oddsFormat']); + } + + public function testSetsDateFormat() + { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->dateFormat('unix'); + + $this->assertEquals('unix', $oddsClient->getParams()['dateForm']); + } + + public function testCommenceTimeFromAndConvertsToIso() + { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->commenceTimeFrom('2024-05-10'); + + $this->assertEquals('2024-05-10T00:00:00Z', $oddsClient->getParams()['commenceTimeFrom']); + } + + public function testCommenceTimeFrom() + { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->commenceTimeFrom('2024-05-10T00:00:00Z', isIsoFormat: true); + + $this->assertEquals('2024-05-10T00:00:00Z', $oddsClient->getParams()['commenceTimeFrom']); + } + + public function testCommenceTimeToAndConvertsToIso() + { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->commenceTimeTo('2024-05-10'); + + $this->assertEquals('2024-05-10T00:00:00Z', $oddsClient->getParams()['commenceTimeTo']); + } + + public function testCommenceTimeTo() + { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->commenceTimeTo('2024-05-10T00:00:00Z', isIsoFormat: true); + + $this->assertEquals('2024-05-10T00:00:00Z', $oddsClient->getParams()['commenceTimeTo']); + } + + public function testCanAddCustomParams() + { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->addParams([ + 'a-new-param' => 'some-value' + ]); + + $this->assertEquals([ + 'api_key' => 'test-api-key', + 'regions' => 'au', + 'oddsFormat' => 'decimal', + 'a-new-param' => 'some-value', + ], $oddsClient->getParams()); + } }