diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 5e10e49..a5f4f33 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -12,6 +12,9 @@ on: jobs: test: runs-on: ubuntu-22.04 + strategy: + matrix: + php-version: ['8.2', '8.3', '8.4'] steps: - uses: actions/checkout@v4 @@ -19,7 +22,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.2' + php-version: ${{ matrix.php-version }} extensions: zip, sqlite3, http coverage: none diff --git a/README.md b/README.md index c2fd02b..63ba386 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Once you call one of the API endpoints which return a response, you can no longe **Another way to define your Client Class** You can bind your Client class at runtime in the AppServiceProvider. Allowing you to simply define the Client -in the constructor of your class, without having to constantly pass the api credentials. +on the container (via the constructor of a class in Laravel), without having to constantly pass the api credentials. ```php $this->app->bind(OddsClient::class, function () { return new OddsClient(config('odds-api.api_key')); diff --git a/composer.json b/composer.json index 71991c8..68a2139 100644 --- a/composer.json +++ b/composer.json @@ -11,12 +11,12 @@ "authors": [ { "name": "Seth Sharp", - "homepage": "https://www.sethsharpportfolio.com/", + "homepage": "https://sethsharp.dev", "role": "Maintainer, Developer" } ], "require": { - "php": "^8.2", + "php": "^8.2 | ^8.3 | ^8.4", "guzzlehttp/guzzle": "^7.8", "nesbot/carbon": "^3.7" }, diff --git a/tests/Pest.php b/tests/Pest.php deleted file mode 100644 index fd279ad..0000000 --- a/tests/Pest.php +++ /dev/null @@ -1,45 +0,0 @@ -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/Unit/OddsClientTest.php b/tests/Unit/OddsClientTest.php deleted file mode 100644 index ca2dcca..0000000 --- a/tests/Unit/OddsClientTest.php +++ /dev/null @@ -1,174 +0,0 @@ -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']); - } - - 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()); - } -} diff --git a/tests/unit/OddsClientTest.php b/tests/unit/OddsClientTest.php new file mode 100644 index 0000000..762727e --- /dev/null +++ b/tests/unit/OddsClientTest.php @@ -0,0 +1,152 @@ +group('odds-client') + ->beforeEach(function () { + $this->app['config']->set('odds-api.default_region', 'au'); + $this->app['config']->set('odds-api.default_odds_format', 'decimal'); + }); + +// Define package providers +function getPackageProviders($app) +{ + return [ + 'SethSharp\OddsApi\OddsApiServiceProvider' + ]; +} + +test('sets up provided api key and default params', function () { + $apiKey = 'test-api-key'; + $oddsClient = new OddsClient($apiKey); + + expect($oddsClient->getApiEndpoint())->toBe('https://api.the-odds-api.com') + ->and($oddsClient->getParams())->toBe([ + 'api_key' => $apiKey, + 'regions' => 'au', + 'oddsFormat' => 'decimal', + ]); +}); + +test('sets provided api endpoint', function () { + $oddsClient = new OddsClient('test-api-key', 'a-new-endpoint'); + + expect($oddsClient->getApiEndpoint())->toBe('a-new-endpoint'); +}); + +test('sets region string', function () { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->setRegion('us'); + + expect($oddsClient->getParams()['regions'])->toBe('us'); +}); + +test('sets markets', function () { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->setMarkets([ + 'h2h', + 'spreads', + 'outrights' + ]); + + expect($oddsClient->getParams()['markets'])->toBe('0=h2h,1=spreads,2=outrights'); +}); + +test('sets bookmakers', function () { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->setBookmakers([ + 'sportsbet', + 'tab', + 'topsport' + ]); + + expect($oddsClient->getParams()['bookmakers'])->toBe('0=sportsbet,1=tab,2=topsport'); +}); + +test('sets events string', function () { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->setEvents('some-event'); + + expect($oddsClient->getParams()['eventIds'])->toBe('some-event'); +}); + +test('sets events array', function () { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->setEvents([ + 'event-1', + 'event-2', + 'event-3', + ]); + + expect($oddsClient->getParams()['eventIds'])->toBe('event-1,event-2,event-3'); +}); + +test('sets odds format', function () { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->oddsFormat('american'); + + expect($oddsClient->getParams()['oddsFormat'])->toBe('american'); +}); + +test('sets date format', function () { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->dateFormat('unix'); + + expect($oddsClient->getParams()['dateForm'])->toBe('unix'); +}); + +test('commence time from and converts to iso', function () { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->commenceTimeFrom('2024-05-10'); + + expect($oddsClient->getParams()['commenceTimeFrom'])->toBe('2024-05-10T00:00:00Z'); +}); + +test('commence time from with iso format', function () { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->commenceTimeFrom('2024-05-10T00:00:00Z', isIsoFormat: true); + + expect($oddsClient->getParams()['commenceTimeFrom'])->toBe('2024-05-10T00:00:00Z'); +}); + +test('commence time to and converts to iso', function () { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->commenceTimeTo('2024-05-10'); + + expect($oddsClient->getParams()['commenceTimeTo'])->toBe('2024-05-10T00:00:00Z'); +}); + +test('commence time to with iso format', function () { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->commenceTimeTo('2024-05-10T00:00:00Z', isIsoFormat: true); + + expect($oddsClient->getParams()['commenceTimeTo'])->toBe('2024-05-10T00:00:00Z'); +}); + +test('can add custom params', function () { + $oddsClient = new OddsClient('test-api-key'); + + $oddsClient->addParams([ + 'a-new-param' => 'some-value' + ]); + + expect($oddsClient->getParams())->toBe([ + 'api_key' => 'test-api-key', + 'regions' => 'au', + 'oddsFormat' => 'decimal', + 'a-new-param' => 'some-value', + ]); +});