|
5 | 5 | namespace WpTestsStarter\Test\WpIntegration;
|
6 | 6 |
|
7 | 7 | use PHPUnit\Framework\TestCase;
|
| 8 | +use WpTestsStarter\Helper\DbUrlParser; |
8 | 9 | use WpTestsStarter\WpTestsStarter;
|
9 | 10 |
|
10 | 11 | class WpTestsStarterDefaultConstantsTest extends TestCase
|
11 | 12 | {
|
12 | 13 | /**
|
13 | 14 | * @runInSeparateProcess
|
14 | 15 | */
|
15 |
| - public function testBoostrapWithDefaultConstants(): void |
| 16 | + public function testBoostrapWithDbUrl(): void |
16 | 17 | {
|
17 | 18 | $baseDir = dirname(dirname(__DIR__)) . '/vendor/wordpress/wordpress';
|
18 | 19 | $wpTestConfig = $baseDir . '/wp-tests-config.php';
|
19 |
| - $testee = new WpTestsStarter($baseDir); |
| 20 | + $testee = new WpTestsStarter( |
| 21 | + $baseDir, |
| 22 | + getenv('WPTS_DB_URL') |
| 23 | + ); |
| 24 | + $testee->bootstrap(); |
20 | 25 |
|
21 |
| - // defined in phpunit-integration.xml |
22 |
| - $testee->useDbName(Db\NAME) |
23 |
| - ->useDbUser(Db\USER) |
24 |
| - ->useDbCharset(Db\USER) |
25 |
| - ->useDbPassword(Db\PASSWORD) |
26 |
| - ->useDbHost(Db\HOST) |
27 |
| - ->useDbCharset(Db\CHARSET) |
28 |
| - ->useDbCollation(Db\COLLATE) |
29 |
| - ->useTablePrefix(Db\TABLE_PREFIX); |
| 26 | + $this->assertFileExists($wpTestConfig); |
| 27 | + $config_data = file_get_contents($wpTestConfig); |
30 | 28 |
|
| 29 | + self::assertMatchesRegularExpression( |
| 30 | + '~define\(\s\'ABSPATH\',\s\'[^\']+\'~', |
| 31 | + $config_data |
| 32 | + ); |
| 33 | + self::assertInstanceOf( |
| 34 | + \wpdb::class, |
| 35 | + $GLOBALS['wpdb'] |
| 36 | + ); |
| 37 | + self::assertTrue( |
| 38 | + $GLOBALS['wpdb']->check_connection() |
| 39 | + ); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @runInSeparateProcess |
| 44 | + */ |
| 45 | + public function testBoostrapWithSetters(): void |
| 46 | + { |
| 47 | + $baseDir = dirname(dirname(__DIR__)) . '/vendor/wordpress/wordpress'; |
| 48 | + $wpTestConfig = $baseDir . '/wp-tests-config.php'; |
| 49 | + |
| 50 | + $credentials = (new DbUrlParser()) |
| 51 | + ->parse(getenv('WPTS_DB_URL')); |
| 52 | + |
| 53 | + $testee = new WpTestsStarter($baseDir); |
| 54 | + |
| 55 | + $credentials['host'] and $testee->useDbHost($credentials['host']); |
| 56 | + $credentials['user'] and $testee->useDbUser($credentials['user']); |
| 57 | + $credentials['password'] and $testee->useDbPassword($credentials['password']); |
| 58 | + $credentials['db'] and $testee->useDbName($credentials['db']); |
| 59 | + $credentials['table_prefix'] and $testee->useTablePrefix($credentials['table_prefix']); |
| 60 | + $credentials['charset'] and $testee->useDbCharset($credentials['charset']); |
| 61 | + $credentials['collation'] and $testee->useDbCollation($credentials['collation']); |
31 | 62 | $testee->bootstrap();
|
32 | 63 |
|
33 | 64 | $this->assertFileExists($wpTestConfig);
|
34 | 65 | $config_data = file_get_contents($wpTestConfig);
|
35 |
| - self::assertMatchesRegularExpression('~define\(\s\'ABSPATH\',\s\'[^\']+\'~', $config_data); |
| 66 | + |
| 67 | + self::assertMatchesRegularExpression( |
| 68 | + '~define\(\s\'ABSPATH\',\s\'[^\']+\'~', |
| 69 | + $config_data |
| 70 | + ); |
| 71 | + self::assertInstanceOf( |
| 72 | + \wpdb::class, |
| 73 | + $GLOBALS['wpdb'] |
| 74 | + ); |
| 75 | + self::assertTrue( |
| 76 | + $GLOBALS['wpdb']->check_connection() |
| 77 | + ); |
36 | 78 | }
|
37 | 79 | }
|
0 commit comments