1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
<?php
namespace Phing\Test\Task\System\Condition;
use Phing\Project;
use Phing\Test\Support\BuildFileTest;
/**
* Tests PDOSQLExecTask as condition.
*
* @author Jawira Portugal <dev@tugal.be>
*
* @requires extension pdo_mysql
* @internal
*/
#[\PHPUnit\Framework\Attributes\RequiresPhpExtension('pdo_mysql')]
class PDOSQLExecTaskConditionTest extends BuildFileTest
{
public function setUp(): void
{
$this->configureProject(
PHING_TEST_BASE . '/etc/tasks/ext/PDOSQLExecTaskConditionTest.xml'
);
}
public function testUrlIsRequiredException(): void
{
$this->expectSpecificBuildException(
__FUNCTION__,
'url property not set in database condition',
'url is required'
);
}
public function testFalseWhenInvalidHost(): void
{
$this->executeTarget(__FUNCTION__);
$this->assertInLogs('Trying to reach mysql:host=dummy', Project::MSG_DEBUG);
$this->assertInLogs('SQLSTATE[HY000] [2002]', Project::MSG_VERBOSE);
$this->assertInLogs('pdosqlexec condition returned false', Project::MSG_INFO);
}
public function testFalseWhenInvalidDriver(): void
{
$this->executeTarget(__FUNCTION__);
$this->assertInLogs('Trying to reach invalid:host=localhost', Project::MSG_DEBUG);
$this->assertInLogs('could not find driver', Project::MSG_VERBOSE);
$this->assertInLogs('pdosqlexec condition returned false', Project::MSG_INFO);
}
public function testCompatibleWithConditionTask(): void
{
$this->executeTarget(__FUNCTION__);
$this->assertPropertyEquals('condition.result', 'condition-not-met');
$this->assertInLogs('Trying to reach mysql:host=localhost', Project::MSG_DEBUG);
}
public function testCompatibleWithWaitForTask(): void
{
$this->executeTarget(__FUNCTION__);
$this->assertPropertyEquals('waitfor.timeout', 'true');
$this->assertInLogs('Trying to reach mysql:host=localhost', Project::MSG_DEBUG);
}
public function testSuccessfulCondition(): void
{
$this->markTestSkipped('This test connects to a public MySQL server.');
$this->executeTarget(__FUNCTION__);
$this->assertInLogs('pdosqlexec condition returned true', Project::MSG_INFO);
}
}
|