Skip to content

Commit

Permalink
Updating TestCase to publish migrations before running
Browse files Browse the repository at this point in the history
  • Loading branch information
mchev committed May 24, 2024
1 parent fbc1db5 commit f72f7d2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .phpunit.cache/test-results
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":1,"defects":{"Mchev\\Banhammer\\Tests\\Unit\\IPBannedMiddlewareTest::it_blocks_the_banned_ip":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_banned":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_with_metas":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_multiple_ip_are_banned":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_can_be_created":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_unbanned":8},"times":{"Mchev\\Banhammer\\Tests\\Unit\\IPBannedMiddlewareTest::it_blocks_the_banned_ip":0.001,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_with_metas":0,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_unbanned":0,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_banned":0.021,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_multiple_ip_are_banned":0,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_can_be_created":0,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_from_non_blocked_country":0.007,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_blocks_request_from_blocked_country":0.001,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_cache_is_present":0,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_country_check_fails":0.006}}
{"version":1,"defects":{"Mchev\\Banhammer\\Tests\\Unit\\IPBannedMiddlewareTest::it_blocks_the_banned_ip":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_banned":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_with_metas":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_multiple_ip_are_banned":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_can_be_created":8,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_unbanned":8},"times":{"Mchev\\Banhammer\\Tests\\Unit\\IPBannedMiddlewareTest::it_blocks_the_banned_ip":0.002,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_with_metas":0.003,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_unbanned":0.002,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_is_banned":0.002,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_multiple_ip_are_banned":0.013,"Mchev\\Banhammer\\Tests\\Unit\\IPBanTest::test_ip_ban_can_be_created":0.001,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_from_non_blocked_country":0.008,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_blocks_request_from_blocked_country":0.021,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_cache_is_present":0.001,"Mchev\\Banhammer\\Tests\\Unit\\BlockByCountryMiddlewareTest::it_allows_request_when_country_check_fails":0.001}}
21 changes: 21 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

abstract class TestCase extends Orchestra
{

protected function setUp(): void
{
parent::setUp();
$this->publishAndRunMigrations();
}

protected function getEnvironmentSetUp($app): void
{
// Load the .env file
Expand All @@ -21,4 +28,18 @@ protected function getPackageProviders($app): array
'Mchev\Banhammer\BanhammerServiceProvider',
];
}

protected function publishAndRunMigrations(): void
{
// Publish the package migrations
$this->artisan('vendor:publish', [
'--provider' => 'Mchev\Banhammer\BanhammerServiceProvider',
'--tag' => 'banhammer-migrations',
'--force' => true,
])->run();

// Run the migrations
$this->artisan('migrate', ['--database' => 'testing'])->run();
}

}

0 comments on commit f72f7d2

Please sign in to comment.