Skip to content

Commit

Permalink
Use PHPUnit 8
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Aug 25, 2020
1 parent 8cc29f9 commit bca99ef
Show file tree
Hide file tree
Showing 24 changed files with 164 additions and 191 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.phpunit.result.cache
build
composer.lock
vendor
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ language: php

php:
- 7.2
- 7.3
- 7.4
- nightly

matrix:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

PACKAGE_NAME = icanboogie/activerecord
PACKAGE_VERSION = 5.0
PHPUNIT_VERSION = phpunit-7.phar
PHPUNIT_VERSION = phpunit-8.phar
PHPUNIT_FILENAME = build/$(PHPUNIT_VERSION)
PHPUNIT = php $(PHPUNIT_FILENAME)

Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
},
"minimum-stability": "dev",
"prefer-stable": true,
"prefer-dist": true,
"require": {
"php": "^7.2",
"php": ">=7.2",
"ext-pdo": "*",
"icanboogie/prototype": "^5.0",
"icanboogie/inflector": "^1.4",
"icanboogie/inflector": "^1.4|^2.0",
"icanboogie/datetime": "^1.2",
"icanboogie/validate": "^0.2"
},
Expand Down
6 changes: 3 additions & 3 deletions lib/ActiveRecord/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public function select($expression): self
*/
public function join($expression, $options = []): self
{
if (\is_string($expression) && $expression{0} == ':')
if (\is_string($expression) && $expression[0] == ':')
{
$expression = $this->model->models[\substr($expression, 1)];
}
Expand Down Expand Up @@ -724,13 +724,13 @@ private function deferred_parse_conditions(...$conditions_and_args): array
$conditions_args = \array_merge($conditions_args, $arg->args);
}

$c .= ' AND `' . ($column{0} == '!' ? \substr($column, 1) . '` NOT' : $column . '`') . ' IN(' . $joined . ')';
$c .= ' AND `' . ($column[0] == '!' ? \substr($column, 1) . '` NOT' : $column . '`') . ' IN(' . $joined . ')';
}
else
{
$conditions_args[] = $arg;

$c .= ' AND `' . ($column{0} == '!' ? \substr($column, 1) . '` !' : $column . '` ') . '= ?';
$c .= ' AND `' . ($column[0] == '!' ? \substr($column, 1) . '` !' : $column . '` ') . '= ?';
}
}

Expand Down
15 changes: 4 additions & 11 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<testsuites>
Expand All @@ -18,7 +11,7 @@
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="false">
<whitelist>
<directory suffix=".php">./lib</directory>
</whitelist>
</filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

use ICanBoogie\ActiveRecord;
use ICanBoogie\ActiveRecord\Model;
use PHPUnit\Framework\TestCase;

class RunTimeActiveRecordCacheTest extends \PHPUnit\Framework\TestCase
class RunTimeActiveRecordCacheTest extends TestCase
{
public function test_cache()
{
Expand All @@ -24,15 +25,15 @@ public function test_cache()
$model = $this
->getMockBuilder(Model::class)
->disableOriginalConstructor()
->setMethods([ 'get_primary'])
->onlyMethods([ 'get_id', 'get_primary'])
->getMock();
$model
->expects($this->any())
->method('get_id')
->willReturn('madonna');
$model
->method('get_primary')
->willReturn($primary);

/* @var $model Model */

$record = new ActiveRecord($model);
$record->$primary = $key;

Expand Down
22 changes: 7 additions & 15 deletions tests/ActiveRecord/ConnectionCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ConnectionCollectionTest extends \PHPUnit\Framework\TestCase
{
private $connections;

public function setUp()
protected function setUp(): void
{
$this->connections = new ConnectionCollection
([
Expand Down Expand Up @@ -54,19 +54,17 @@ public function test_should_get_connection()

/**
* @depends test_should_get_connection
* @expectedException \ICanBoogie\ActiveRecord\ConnectionAlreadyEstablished
*/
public function test_should_throw_an_exception_on_setting_established_connection()
{
$this->connections['one'];
$this->expectException(\ICanBoogie\ActiveRecord\ConnectionAlreadyEstablished::class);
$this->connections['one'] = [ 'dsn' => 'sqlite::memory:' ];
}

/**
* @expectedException \ICanBoogie\ActiveRecord\ConnectionNotDefined
*/
public function test_should_throw_an_exception_on_getting_undefined_connection()
{
$this->expectException(\ICanBoogie\ActiveRecord\ConnectionNotDefined::class);
$this->connections['undefined'];
}

Expand All @@ -80,11 +78,9 @@ public function test_should_set_connection_while_it_is_not_established()
$this->assertInstanceOf(Connection::class, $this->connections['two']);
}

/**
* @expectedException \InvalidArgumentException
*/
public function test_should_throw_an_exception_on_setting_invalid_connection()
{
$this->expectException(\InvalidArgumentException::class);
$this->connections['invalid'] = [

'd_s_n' => 'sqlite::memory:'
Expand All @@ -105,27 +101,23 @@ public function test_should_unset_connection_definition()

/**
* @depends test_should_get_connection
* @expectedException \ICanBoogie\ActiveRecord\ConnectionAlreadyEstablished
*/
public function test_should_throw_exception_on_unsetting_established_connection()
{
$this->connections['one'];
$this->expectException(\ICanBoogie\ActiveRecord\ConnectionAlreadyEstablished::class);
unset($this->connections['one']);
}

/**
* @expectedException \ICanBoogie\ActiveRecord\ConnectionNotDefined
*/
public function testConnectionNotDefined()
{
$this->expectException(\ICanBoogie\ActiveRecord\ConnectionNotDefined::class);
$this->connections['two'];
}

/**
* @expectedException \ICanBoogie\ActiveRecord\ConnectionNotEstablished
*/
public function testConnectionNotEstablished()
{
$this->expectException(\ICanBoogie\ActiveRecord\ConnectionNotEstablished::class);
$this->connections['bad'];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ActiveRecord/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ConnectionTest extends \PHPUnit\Framework\TestCase
*/
private $connection;

public function setUp()
protected function setUp(): void
{
$this->id = 'db' . uniqid();

Expand Down
10 changes: 5 additions & 5 deletions tests/ActiveRecord/Driver/MySQLDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public function test_multicolumn_primary_key()
$connection
->expects($this->any())
->method('exec')
->willReturnCallback(function($statement) {
->willReturnCallback(function(string $statement) {

$this->assertContains("`id` BIGINT UNSIGNED NOT NULL", $statement);
$this->assertContains("`name` VARCHAR( 255 ) NOT NULL", $statement);
$this->assertContains("`value` TEXT NOT NULL", $statement);
$this->assertContains("PRIMARY KEY(`id`, `name`)", $statement);
$this->assertStringContainsString("`id` BIGINT UNSIGNED NOT NULL", $statement);
$this->assertStringContainsString("`name` VARCHAR( 255 ) NOT NULL", $statement);
$this->assertStringContainsString("`value` TEXT NOT NULL", $statement);
$this->assertStringContainsString("PRIMARY KEY(`id`, `name`)", $statement);

});

Expand Down
2 changes: 1 addition & 1 deletion tests/ActiveRecord/DriverNotDefinedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public function test_exception()
$driver_name = uniqid();
$exception = new DriverNotDefined($driver_name);
$this->assertSame($driver_name, $exception->driver_name);
$this->assertContains($driver_name, $exception->getMessage());
$this->assertStringContainsString($driver_name, $exception->getMessage());
}
}
6 changes: 2 additions & 4 deletions tests/ActiveRecord/HasManyRelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HasManyRelationTest extends \PHPUnit\Framework\TestCase
private $articles;
private $comments;

public function setUp()
protected function setUp(): void
{
$connections = new ConnectionCollection([

Expand Down Expand Up @@ -97,11 +97,9 @@ public function test_getters()
$this->assertSame($this->articles->primary, $relation->foreign_key);
}

/**
* @expectedException \ICanBoogie\ActiveRecord\RelationNotDefined
*/
public function test_undefined_relation()
{
$this->expectException(\ICanBoogie\ActiveRecord\RelationNotDefined::class);
$this->articles->relations['undefined_relation'];
}

Expand Down
10 changes: 4 additions & 6 deletions tests/ActiveRecord/ModelCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ModelCollectionTest extends \PHPUnit\Framework\TestCase
*/
private $definitions;

public function setUp()
protected function setUp(): void
{
$this->connections = new ConnectionCollection([

Expand Down Expand Up @@ -78,7 +78,7 @@ public function setUp()
public function test_get_instances()
{
$models = $this->models;
$this->assertInternalType('array', $models->definitions);
$this->assertIsArray($models->definitions);
$this->assertEquals([], $models->instances);
$this->assertInstanceOf(Model::class, $models['articles']);
$this->assertInstanceOf(Model::class, $models['comments']);
Expand All @@ -94,7 +94,7 @@ public function test_get_instances()
public function test_get_definitions()
{
$models = $this->models;
$this->assertInternalType('array', $models->definitions);
$this->assertIsArray($models->definitions);
$this->assertEquals([ 'articles', 'comments', 'other' ], array_keys($models->definitions));
}

Expand Down Expand Up @@ -143,11 +143,9 @@ public function test_should_get_same()
$this->assertSame($articles, $this->models['articles']);
}

/**
* @expectedException \ICanBoogie\ActiveRecord\ModelNotDefined
*/
public function test_offset_get_undefined()
{
$this->expectException(\ICanBoogie\ActiveRecord\ModelNotDefined::class);
$this->models[uniqid()];
}

Expand Down

0 comments on commit bca99ef

Please sign in to comment.