add query error test

This commit is contained in:
prolic 2018-06-30 01:24:35 +08:00
parent 2f18fa41c4
commit 27d70df99c
No known key found for this signature in database
GPG Key ID: 29722F9F48E9DE59
5 changed files with 60 additions and 2 deletions

View File

@ -14,13 +14,20 @@
"amphp/amp": "^2"
},
"require-dev": {
"amphp/php-cs-fixer-config": "dev-master"
"amphp/php-cs-fixer-config": "dev-master",
"amphp/phpunit-util": "^1",
"phpunit/phpunit": "^6"
},
"autoload": {
"psr-4": {
"Amp\\Sql\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Amp\\Sql\\Test\\": "test"
}
},
"config": {
"platform": {
"php": "7.0.0"

28
phpunit.xml.dist Normal file
View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="test/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Amp Sql Client">
<directory>test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<listeners>
<listener class="Amp\PHPUnit\LoopReset"/>
</listeners>
</phpunit>

View File

@ -8,7 +8,7 @@ class QueryError extends \Error
public function __construct(string $message, string $query = "", \Throwable $previous = null)
{
if ($query != "") {
if ($query !== "") {
$this->query = $query;
}
parent::__construct($message, 0, $previous);

20
test/QueryErrorTest.php Normal file
View File

@ -0,0 +1,20 @@
<?php
namespace Amp\Sql\Test;
use Amp\PHPUnit\TestCase;
use Amp\Sql\QueryError;
class QueryErrorTest extends TestCase
{
/**
* @test
*/
public function it_passed_query_along()
{
$error = new QueryError('error', 'SELECT * FROM foo');
$this->assertSame('SELECT * FROM foo', $error->getQuery());
$this->assertStringStartsWith("Amp\Sql\QueryError: error\nCurrent query was SELECT * FROM foo", (string) $error);
}
}

3
test/bootstrap.php Normal file
View File

@ -0,0 +1,3 @@
<?php
require __DIR__.'/../vendor/autoload.php';