From d151d6c3cb4a84cfdd5a05afb6b45852565d066d Mon Sep 17 00:00:00 2001 From: salahhusa9 Date: Sat, 11 Nov 2023 15:24:41 +0100 Subject: [PATCH] TESTS --- src/Exceptions/GithubConfigException.php | 18 +++ src/RepositorySource/GithubRepository.php | 11 +- .../RepositorySource/GithubRepositoryTest.php | 119 ++++++++++++++++++ 3 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 src/Exceptions/GithubConfigException.php create mode 100644 tests/RepositorySource/GithubRepositoryTest.php diff --git a/src/Exceptions/GithubConfigException.php b/src/Exceptions/GithubConfigException.php new file mode 100644 index 0000000..6545f9e --- /dev/null +++ b/src/Exceptions/GithubConfigException.php @@ -0,0 +1,18 @@ +set('updater.github_token', 'salahhusa9'); + config()->set('updater.github_username', 'salahhusa9'); + config()->set('updater.github_repository', 'laravel-updater'); + + $githubRepository = new GithubRepository(); + + $this->assertTrue($githubRepository->checkConfig()); + } + + /** @test */ + public function config_check_exception() + { + $this->expectException(GithubConfigException::class); + + $githubRepository = new GithubRepository(); + + $this->assertTrue($githubRepository->checkConfig()); + } + + /** @test */ + public function it_can_get_latest_version() + { + // set env + config()->set('updater.github_token', 'salahhusa9'); + config()->set('updater.github_username', 'salahhusa9'); + config()->set('updater.github_repository', 'laravel-updater'); + + Http::fake([ + 'https://api.github.com/repos/salahhusa9/laravel-updater/releases/latest' => Http::response([ + 'tag_name' => 'v1.0.0', + ], 200), + ]); + + $githubRepository = new GithubRepository(); + + $this->assertEquals('v1.0.0', $githubRepository->getLatestVersion()); + } + + /** @test */ + public function it_can_get_latest_version_data() + { + // set env + config()->set('updater.github_token', 'salahhusa9'); + config()->set('updater.github_username', 'salahhusa9'); + config()->set('updater.github_repository', 'laravel-updater'); + + Http::fake([ + 'https://api.github.com/repos/salahhusa9/laravel-updater/releases/latest' => Http::response([ + 'tag_name' => 'v1.0.0', + ], 200), + ]); + + $githubRepository = new GithubRepository(); + + $this->assertIsArray($githubRepository->getLatestVersionData()->toArray()); + } + + /** @test */ + public function it_can_get_versions() + { + // set env + config()->set('updater.github_token', 'salahhusa9'); + config()->set('updater.github_username', 'salahhusa9'); + config()->set('updater.github_repository', 'laravel-updater'); + + Http::fake([ + 'https://api.github.com/repos/salahhusa9/laravel-updater/releases' => Http::response([ + [ + 'tag_name' => 'v1.0.0', + ], + [ + 'tag_name' => 'v1.0.1', + ], + ], 200), + ]); + + $githubRepository = new GithubRepository(); + + $this->assertIsArray($githubRepository->getVersions()); + } + + /** @test */ + public function it_can_get_versions_data() + { + // set env + config()->set('updater.github_token', 'salahhusa9'); + config()->set('updater.github_username', 'salahhusa9'); + config()->set('updater.github_repository', 'laravel-updater'); + + Http::fake([ + 'https://api.github.com/repos/salahhusa9/laravel-updater/releases' => Http::response([ + [ + 'tag_name' => 'v1.0.0', + ], + [ + 'tag_name' => 'v1.0.1', + ], + ], 200), + ]); + + $githubRepository = new GithubRepository(); + + $this->assertIsArray($githubRepository->getVersionsData()->toArray()); + } +}