forked from selahattinunlu/laravel-api-query-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request selahattinunlu#27 from mahmutbayri/feature/add-php…
…unit-tests Implement phpunit.
- Loading branch information
Showing
7 changed files
with
193 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/vendor | ||
/build | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
dist: trusty | ||
language: php | ||
php: | ||
- 5.6 | ||
- 7.0 | ||
install: | ||
- travis_retry composer install --no-interaction --prefer-source | ||
script: | ||
- phpunit --coverage-text --coverage-clover=coverage.clover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Application Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
<php> | ||
</php> | ||
<logging> | ||
<log type="tap" target="build/report.tap"/> | ||
<log type="junit" target="build/report.junit.xml"/> | ||
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/> | ||
<log type="coverage-text" target="build/coverage.txt"/> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
class BaseTestCase extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected function assertArrayContainsArray($needle, $haystack) | ||
{ | ||
foreach ($needle as $key => $val) { | ||
$this->assertArrayHasKey($key, $haystack); | ||
|
||
if (is_array($val)) { | ||
$this->assertArrayContainsArray($val, $haystack[$key]); | ||
} else { | ||
$this->assertEquals($val, $haystack[$key]); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use Illuminate\Http\Request; | ||
use Unlu\Laravel\Api\UriParser; | ||
|
||
class UriParserTest extends BaseTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_gets_query_parameter() | ||
{ | ||
$uriParser = $this->getUriParser(); | ||
|
||
$expected = [ | ||
'type' => 'Basic', | ||
'key' => 'some-param', | ||
'operator' => '=', | ||
'value' => 'some-param-value' | ||
]; | ||
|
||
$this->assertEquals($expected, $uriParser->queryParameter('some-param')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_gets_constant_parameters() | ||
{ | ||
$uriParser = $this->getUriParser(); | ||
|
||
$constants = [ | ||
'order_by', | ||
'group_by', | ||
'limit', | ||
'page', | ||
'columns', | ||
'includes', | ||
'appends', | ||
]; | ||
|
||
$this->assertArrayContainsArray($constants, $uriParser->constantParameters()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_gets_where_parameters() | ||
{ | ||
$uriParser = $this->getUriParser(); | ||
|
||
$expected = [ | ||
[ | ||
'type' => 'Basic', | ||
'key' => 'some-param', | ||
'operator' => '=', | ||
'value' => 'some-param-value' | ||
] | ||
]; | ||
|
||
$this->assertEquals($expected, $uriParser->whereParameters()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_checks_has_query_uri() | ||
{ | ||
$uriParser = $this->getUriParser(); | ||
$this->assertEquals('some-param=some-param-value', $uriParser->hasQueryUri()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_gets_query_uri() | ||
{ | ||
$uriParser = $this->getUriParser(); | ||
$this->assertEquals('some-param=some-param-value', $uriParser->getQueryUri()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_checks_has_query_parameters() | ||
{ | ||
$uriParser = $this->getUriParser(); | ||
$this->assertTrue($uriParser->hasQueryParameters()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_checks_has_query_parameter() | ||
{ | ||
$uriParser = $this->getUriParser(); | ||
$this->assertTrue($uriParser->hasQueryParameter('some-param')); | ||
} | ||
|
||
/** | ||
* @param array $params | ||
* @return UriParser | ||
*/ | ||
protected function getUriParser($params = null) | ||
{ | ||
if(is_null($params)) { | ||
$params = ['some-param' => 'some-param-value']; | ||
} | ||
|
||
$request = Request::create('/some-uri', 'GET', $params); | ||
|
||
return new UriParser($request); | ||
} | ||
} |