From 5967cad71813bb2e17fb845e651ebc571c681d5e Mon Sep 17 00:00:00 2001 From: Daryle Dale De Silva Date: Wed, 20 Jan 2021 15:44:14 +0800 Subject: [PATCH] Support Laravel 8 (#18) * fix tests * add github actions script --- .github/workflows/build.yml | 54 +++++++++++++++++ composer.json | 6 +- phpunit.xml | 3 +- .../DataTable/Columns/Column.php | 4 +- src/Frozennode/Administrator/Fields/Field.php | 2 +- .../Fields/Relationships/BelongsToMany.php | 4 +- src/Frozennode/Administrator/Menu.php | 6 +- tests/Actions/ActionFactoryTest.php | 14 ++--- tests/Actions/ActionTest.php | 23 +++++--- tests/Config/ConfigFactoryTest.php | 14 +++-- tests/Config/ConfigTest.php | 20 ++++--- tests/Config/Model/ModelConfigTest.php | 18 +++++- tests/Config/Settings/SettingsConfigTest.php | 13 ++-- tests/DataTable/Columns/ColumnFactoryTest.php | 10 ++-- tests/DataTable/Columns/ColumnTest.php | 20 ++++--- .../Relationships/BelongsToManyTest.php | 6 +- .../Columns/Relationships/BelongsToTest.php | 13 ++-- .../Relationships/HasOneOrManyTest.php | 6 +- .../Relationships/RelationshipTest.php | 9 ++- tests/DataTable/DataTableTest.php | 13 ++-- tests/Fields/BoolTest.php | 18 +++++- tests/Fields/EnumTest.php | 15 ++++- tests/Fields/FieldFactoryTest.php | 59 ++++++++++--------- tests/Fields/FieldTest.php | 41 ++++++++++--- tests/Fields/FileTest.php | 9 ++- tests/Fields/KeyTest.php | 12 +++- tests/Fields/NumberTest.php | 9 ++- .../Relationships/BelongsToManyTest.php | 38 ++++++++---- tests/Fields/Relationships/BelongsToTest.php | 15 ++++- .../Fields/Relationships/HasOneOrManyTest.php | 12 +++- .../Fields/Relationships/RelationshipTest.php | 9 ++- tests/Fields/TextTest.php | 12 +++- tests/Fields/TimeTest.php | 18 +++++- tests/MenuTest.php | 20 +++++-- tests/ValidatorTest.php | 9 ++- 35 files changed, 379 insertions(+), 175 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..7830d726c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,54 @@ +name: CI +on: + push: + branches: + - '**' + tags-ignore: + - '**' +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: [ '7.4', '8.0' ] + laravel: [ '6.*', '7.*', '8.*' ] + prefer: [ 'prefer-lowest', 'prefer-stable' ] + name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} --${{ matrix.prefer }} + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + tools: composer:v2, phpunit + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup problem matchers for PHP + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.prefer }}- + restore-keys: ${{ runner.os }}-composer-${{ matrix.prefer }}- + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update + composer update --${{ matrix.prefer }} --prefer-dist --no-interaction --no-suggest + + - name: Test with phpunit + run: phpunit diff --git a/composer.json b/composer.json index b961d0128..1255b32db 100644 --- a/composer.json +++ b/composer.json @@ -14,12 +14,12 @@ "issues": "https://github.com/FrozenNode/Laravel-Administrator/issues" }, "require": { - "php": ">=5.4.0", - "laravel/framework": "^6.0|^7.0", + "php": "^7.4|^8.0", + "laravel/framework": "^6.0|^7.0|^8.0", "ckeditor/ckeditor": "4.*" }, "require-dev": { - "mockery/mockery": "~0.9" + "mockery/mockery": "^1.3.1" }, "autoload": { "psr-0": { diff --git a/phpunit.xml b/phpunit.xml index 4b0b204fb..60abb45bd 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,8 +7,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true" - syntaxCheck="false" + stopOnFailure="false" > diff --git a/src/Frozennode/Administrator/DataTable/Columns/Column.php b/src/Frozennode/Administrator/DataTable/Columns/Column.php index ac60b198a..d13e3cd5c 100644 --- a/src/Frozennode/Administrator/DataTable/Columns/Column.php +++ b/src/Frozennode/Administrator/DataTable/Columns/Column.php @@ -153,7 +153,7 @@ public function build() $options['sort_field'] = $this->validator->arrayGet($options, 'sort_field', $options['column_name']); //if the supplied item is an accessor, make this unsortable for the moment - if (method_exists($model, camel_case('get_'.$options['column_name'].'_attribute')) && $options['column_name'] === $options['sort_field']) + if (method_exists($model, \Illuminate\Support\Str::camel('get_'.$options['column_name'].'_attribute')) && $options['column_name'] === $options['sort_field']) { $options['sortable'] = false; } @@ -165,7 +165,7 @@ public function build() } //now we do some final organization to categorize these columns (useful later in the sorting) - if (method_exists($model, camel_case('get_'.$options['column_name'].'_attribute')) || $select) + if (method_exists($model, \Illuminate\Support\Str::camel('get_'.$options['column_name'].'_attribute')) || $select) { $options['is_computed'] = true; } diff --git a/src/Frozennode/Administrator/Fields/Field.php b/src/Frozennode/Administrator/Fields/Field.php index c065e483e..564379aea 100644 --- a/src/Frozennode/Administrator/Fields/Field.php +++ b/src/Frozennode/Administrator/Fields/Field.php @@ -264,7 +264,7 @@ public function getOption($key) if (!array_key_exists($key, $options)) { - throw new \InvalidArgumentException("An invalid option '$key' was searched for in the '" . $this->userOptions['field_name'] . "' field"); + throw new \InvalidArgumentException("An invalid option '$key' was searched for in the '" . ($this->userOptions['field_name'] ?? null) . "' field"); } return $options[$key]; diff --git a/src/Frozennode/Administrator/Fields/Relationships/BelongsToMany.php b/src/Frozennode/Administrator/Fields/Relationships/BelongsToMany.php index 688a0f908..8b3a363a3 100644 --- a/src/Frozennode/Administrator/Fields/Relationships/BelongsToMany.php +++ b/src/Frozennode/Administrator/Fields/Relationships/BelongsToMany.php @@ -112,7 +112,9 @@ public function filterQuery(QueryBuilder &$query, &$selects = null) $query->whereIn($column2, $value); //add having clauses - $query->havingRaw('COUNT(DISTINCT ' . $query->getConnection()->getTablePrefix() . $column2 . ') = ' . count($value)); + if($value instanceof \Countable || is_array($value)){ + $query->havingRaw('COUNT(DISTINCT ' . $query->getConnection()->getTablePrefix() . $column2 . ') = ' . count($value)); + } //add select field if ($selects && !in_array($column2, $selects)) diff --git a/src/Frozennode/Administrator/Menu.php b/src/Frozennode/Administrator/Menu.php index 21668baf4..82d576f7c 100644 --- a/src/Frozennode/Administrator/Menu.php +++ b/src/Frozennode/Administrator/Menu.php @@ -102,13 +102,13 @@ protected function add(array &$menu, string $item, $key): void $settingsPrefix = $this->configFactory->getSettingsPrefix(); $pagePrefix = $this->configFactory->getPagePrefix(); if (strpos($item, $settingsPrefix) === 0) { - $url = route('admin_settings', array(substr($item, strlen($settingsPrefix)))); + $url = \Illuminate\Support\Facades\URL::route('admin_settings', array(substr($item, strlen($settingsPrefix)))); } elseif (strpos($item, $pagePrefix) === 0) { - $url = route('admin_page', array(substr($item, strlen($pagePrefix)))); + $url = \Illuminate\Support\Facades\URL::route('admin_page', array(substr($item, strlen($pagePrefix)))); } elseif (filter_var($item, FILTER_VALIDATE_URL)) { $url = $item; } else { - $url = route('admin_index', array($item)); + $url = \Illuminate\Support\Facades\URL::route('admin_index', array($item)); } $menu[$url] = $key; } diff --git a/tests/Actions/ActionFactoryTest.php b/tests/Actions/ActionFactoryTest.php index f62ff46cf..5ff23bb44 100644 --- a/tests/Actions/ActionFactoryTest.php +++ b/tests/Actions/ActionFactoryTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class ActionFactoryTest extends \PHPUnit_Framework_TestCase { +class ActionFactoryTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -29,7 +29,7 @@ class ActionFactoryTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -39,7 +39,7 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } @@ -59,21 +59,17 @@ public function testParseDefaults() $this->assertEquals($this->factory->parseDefaults('action', array()), $output); } - /** - * @expectedException InvalidArgumentException - */ public function testParseDefaultsInvalidName() { + $this->expectException(\InvalidArgumentException::class); $this->config->shouldReceive('getDataModel')->once() ->shouldReceive('getOption')->once(); $this->factory->parseDefaults(true, array()); } - /** - * @expectedException InvalidArgumentException - */ public function testParseDefaultsInvalidOptions() { + $this->expectException(\InvalidArgumentException::class); $this->config->shouldReceive('getDataModel')->once() ->shouldReceive('getOption')->once(); $this->factory->parseDefaults('action', true); diff --git a/tests/Actions/ActionTest.php b/tests/Actions/ActionTest.php index 85f2109a8..f0b07ad44 100644 --- a/tests/Actions/ActionTest.php +++ b/tests/Actions/ActionTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class ActionTest extends \PHPUnit_Framework_TestCase { +class ActionTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -29,7 +29,7 @@ class ActionTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -41,11 +41,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testValidates() { $this->validator->shouldReceive('override')->once() @@ -53,11 +56,9 @@ public function testValidates() $this->action->validateOptions(); } - /** - * @expectedException InvalidArgumentException - */ public function testValidateFails() { + $this->expectException(\InvalidArgumentException::class); $this->validator->shouldReceive('override')->once() ->shouldReceive('fails')->once()->andReturn(true) ->shouldReceive('messages')->once()->andReturn(m::mock(array('all' => array()))); @@ -65,6 +66,9 @@ public function testValidateFails() $this->action->validateOptions(); } + /** + * @doesNotPerformAssertions + */ public function testBuild() { $this->action->shouldReceive('buildStringOrCallable')->twice(); @@ -72,6 +76,9 @@ public function testBuild() $this->action->build(); } + /** + * @doesNotPerformAssertions + */ public function testBuildStringOrCallableEmpty() { $this->config->shouldReceive('getDataModel')->once(); @@ -129,11 +136,9 @@ public function testGetOptionSucceeds() $this->assertEquals($this->action->getOption('foo'), 'bar'); } - /** - * @expectedException InvalidArgumentException - */ public function testGetOptionFails() { + $this->expectException(\InvalidArgumentException::class); $this->action->shouldReceive('getOptions')->once()->andReturn(array('action_name' => 'bar')); $this->action->getOption('foo'); } diff --git a/tests/Config/ConfigFactoryTest.php b/tests/Config/ConfigFactoryTest.php index e890cbce1..2153296ed 100644 --- a/tests/Config/ConfigFactoryTest.php +++ b/tests/Config/ConfigFactoryTest.php @@ -4,7 +4,7 @@ use Mockery as m; use Frozennode\Administrator\Config\Factory; -class ConfigFactoryTest extends \PHPUnit_Framework_TestCase { +class ConfigFactoryTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -25,7 +25,7 @@ class ConfigFactoryTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->validator->shouldReceive('override')->once() @@ -35,24 +35,23 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } /** * Tests that the validation is run + * @doesNotPerformAssertions */ public function testValidationRun() { $factory = new Factory($this->validator, $this->validator, array()); } - /** - * @expectedException InvalidArgumentException - */ public function testValidationErrorThrowsException() { + $this->expectException(\InvalidArgumentException::class); $this->validator->shouldReceive('fails')->once()->andReturn(true) ->shouldReceive('messages')->once()->andReturn(m::mock(array('all' => array()))); @@ -76,6 +75,9 @@ public function testMakeReturnsFalse() $this->assertEquals($factory->make('some_model'), false); } + /** + * @doesNotPerformAssertions + */ public function testUpdateConfigOptions() { $config = m::mock('Frozennode\Administrator\Config\Config'); diff --git a/tests/Config/ConfigTest.php b/tests/Config/ConfigTest.php index 701da1dba..17603dd99 100644 --- a/tests/Config/ConfigTest.php +++ b/tests/Config/ConfigTest.php @@ -4,7 +4,7 @@ use Mockery as m; use Frozennode\Administrator\Config\Config; -class ConfigTest extends \PHPUnit_Framework_TestCase { +class ConfigTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -30,7 +30,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Config', array($this->validator, $this->validator, array('name' => 'model_name')))->makePartial(); @@ -39,11 +39,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testValidates() { $this->validator->shouldReceive('override')->once() @@ -51,17 +54,18 @@ public function testValidates() $this->config->validateOptions(); } - /** - * @expectedException InvalidArgumentException - */ public function testValidateFails() { + $this->expectException(\InvalidArgumentException::class); $this->validator->shouldReceive('override')->once() ->shouldReceive('fails')->once()->andReturn(true) ->shouldReceive('messages')->once()->andReturn(m::mock(array('all' => array()))); $this->config->validateOptions(); } + /** + * @doesNotPerformAssertions + */ public function testBuild() { $this->config->build(); @@ -80,11 +84,9 @@ public function testGetOptionWorks() $this->assertEquals($this->config->getOption('name'), 'model_name'); } - /** - * @expectedException InvalidArgumentException - */ public function testGetOptionThrowsException() { + $this->expectException(\InvalidArgumentException::class); $this->config->shouldReceive('getOptions')->once()->andReturn(array('name' => 'model_name')); $this->config->getOption('foo'); } diff --git a/tests/Config/Model/ModelConfigTest.php b/tests/Config/Model/ModelConfigTest.php index 780102423..e4f05a078 100644 --- a/tests/Config/Model/ModelConfigTest.php +++ b/tests/Config/Model/ModelConfigTest.php @@ -12,7 +12,7 @@ public function find() {return $this;} public function __unset($name) {unset($this->$name);} } -class ModelConfigTest extends \PHPUnit_Framework_TestCase { +class ModelConfigTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -31,7 +31,7 @@ class ModelConfigTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config', array($this->validator, $this->validator, array()))->makePartial(); @@ -40,7 +40,7 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } @@ -288,6 +288,9 @@ public function testSaveValidateFails() $this->assertEquals($this->config->save($input, $fields, $actionPermissions), 'some error'); } + /** + * @doesNotPerformAssertions + */ public function testFillModel() { $input = m::mock('Illuminate\Http\Request'); @@ -356,6 +359,9 @@ public function testGetModelStaticValidationRulesNoRules() $this->assertEquals($this->config->getModelStaticValidationRules(), false); } + /** + * @doesNotPerformAssertions + */ public function testSaveRelationships() { $model = m::mock('Illuminate\Database\Eloquent\Model'); @@ -381,6 +387,9 @@ public function testGetModelLinkNotCallable() $this->assertEquals($this->config->getModelLink(), false); } + /** + * @doesNotPerformAssertions + */ public function testRunQueryFilterNoFilter() { $query = m::mock('Illuminate\Database\Query\Builder'); @@ -389,6 +398,9 @@ public function testRunQueryFilterNoFilter() $this->config->runQueryFilter($query); } + /** + * @doesNotPerformAssertions + */ public function testRunQueryFilterWithFilter() { $filter = function($query) { diff --git a/tests/Config/Settings/SettingsConfigTest.php b/tests/Config/Settings/SettingsConfigTest.php index 7a63d0a58..bce7d8a2b 100644 --- a/tests/Config/Settings/SettingsConfigTest.php +++ b/tests/Config/Settings/SettingsConfigTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class SettingsConfigTest extends \PHPUnit_Framework_TestCase { +class SettingsConfigTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -22,7 +22,7 @@ class SettingsConfigTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Settings\Config', array($this->validator, $this->validator, array()))->makePartial(); @@ -31,7 +31,7 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } @@ -43,6 +43,9 @@ public function testGetStoragePathAddsAndTrimsTrailingSlash() $this->assertEquals($this->config->getStoragePath(), '/test/path/two/'); } + /** + * @doesNotPerformAssertions + */ public function testFetchData() { $this->config->shouldReceive('setDataModel')->once() @@ -160,11 +163,9 @@ public function testPutToJson() rmdir($path); } - /** - * @expectedException InvalidArgumentException - */ public function testPutToJsonNotWritableError() { + $this->expectException(\InvalidArgumentException::class); $path = __DIR__ . '/bar/'; $this->config->shouldReceive('getStoragePath')->once()->andReturn($path) ->shouldReceive('getOption')->once()->andReturn('foo'); diff --git a/tests/DataTable/Columns/ColumnFactoryTest.php b/tests/DataTable/Columns/ColumnFactoryTest.php index fc4863e9b..4ad1544c4 100644 --- a/tests/DataTable/Columns/ColumnFactoryTest.php +++ b/tests/DataTable/Columns/ColumnFactoryTest.php @@ -14,7 +14,7 @@ class ColumnStub { public $foo = 'bar'; } -class ColumnFactoryTest extends \PHPUnit_Framework_TestCase { +class ColumnFactoryTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -55,7 +55,7 @@ class ColumnFactoryTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -66,7 +66,7 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } @@ -142,11 +142,9 @@ public function testParseOptionsWithOptionsReturnsIndexedArray() $this->assertEquals($this->factory->parseOptions('funky', array('title' => 'Funky')), array('column_name' => 'funky', 'title' => 'Funky')); } - /** - * @expectedException InvalidArgumentException - */ public function testParseOptionsInvalidValueThrowsError() { + $this->expectException(\InvalidArgumentException::class); $this->config->shouldReceive('getOption')->once()->andReturn(''); $this->factory->parseOptions(0, null); } diff --git a/tests/DataTable/Columns/ColumnTest.php b/tests/DataTable/Columns/ColumnTest.php index 5051eaf5b..4d7a36c6c 100644 --- a/tests/DataTable/Columns/ColumnTest.php +++ b/tests/DataTable/Columns/ColumnTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class ColumnTest extends \PHPUnit_Framework_TestCase { +class ColumnTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -36,7 +36,7 @@ class ColumnTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -50,11 +50,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testValidates() { $this->column->shouldReceive('getRules')->once()->andReturn(array()); @@ -63,11 +66,9 @@ public function testValidates() $this->column->validateOptions(); } - /** - * @expectedException InvalidArgumentException - */ public function testValidateFails() { + $this->expectException(\InvalidArgumentException::class); $this->column->shouldReceive('getRules')->once()->andReturn(array()); $this->validator->shouldReceive('override')->once() ->shouldReceive('fails')->once()->andReturn(true) @@ -76,6 +77,9 @@ public function testValidateFails() $this->column->validateOptions(); } + /** + * @doesNotPerformAssertions + */ public function testBuild() { $this->config->shouldReceive('getDataModel')->once()->andReturn(m::mock(array())); @@ -120,11 +124,9 @@ public function testGetOptionSucceeds() $this->assertEquals($this->column->getOption('foo'), 'bar'); } - /** - * @expectedException InvalidArgumentException - */ public function testGetOptionFails() { + $this->expectException(\InvalidArgumentException::class); $this->column->shouldReceive('getOptions')->once()->andReturn(array('column_name' => 'bar')); $this->column->getOption('foo'); } diff --git a/tests/DataTable/Columns/Relationships/BelongsToManyTest.php b/tests/DataTable/Columns/Relationships/BelongsToManyTest.php index 57a2c75f9..b2faa3394 100644 --- a/tests/DataTable/Columns/Relationships/BelongsToManyTest.php +++ b/tests/DataTable/Columns/Relationships/BelongsToManyTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class BelongsToManyTest extends \PHPUnit_Framework_TestCase { +class BelongsToManyTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -36,7 +36,7 @@ class BelongsToManyTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -50,7 +50,7 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } diff --git a/tests/DataTable/Columns/Relationships/BelongsToTest.php b/tests/DataTable/Columns/Relationships/BelongsToTest.php index 80c31fbd0..37fbc0a87 100644 --- a/tests/DataTable/Columns/Relationships/BelongsToTest.php +++ b/tests/DataTable/Columns/Relationships/BelongsToTest.php @@ -27,7 +27,7 @@ public function btdeepnest() { } } -class BelongsToTest extends \PHPUnit_Framework_TestCase { +class BelongsToTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -60,7 +60,7 @@ class BelongsToTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -74,11 +74,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testBuild() { $relevantModel = m::mock(array('method' => m::mock(array('getRelated' => m::mock(array('getTable' => '')))))); @@ -124,11 +127,9 @@ public function testGetNestedRelationshipsDeepNest() $this->assertEquals(sizeof($nested['models']), 4); } - /** - * @expectedException InvalidArgumentException - */ public function testGetNestedRelationshipsFails() { + $this->expectException(\InvalidArgumentException::class); $name = 'nope'; $stub = new BelongsToStub; $this->config->shouldReceive('getDataModel')->once()->andReturn($stub) diff --git a/tests/DataTable/Columns/Relationships/HasOneOrManyTest.php b/tests/DataTable/Columns/Relationships/HasOneOrManyTest.php index fe0b7130d..57b6fb3ef 100644 --- a/tests/DataTable/Columns/Relationships/HasOneOrManyTest.php +++ b/tests/DataTable/Columns/Relationships/HasOneOrManyTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class HasOneOrManyTest extends \PHPUnit_Framework_TestCase { +class HasOneOrManyTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -36,7 +36,7 @@ class HasOneOrManyTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -50,7 +50,7 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } diff --git a/tests/DataTable/Columns/Relationships/RelationshipTest.php b/tests/DataTable/Columns/Relationships/RelationshipTest.php index 51f74753a..4e7fa3bcf 100644 --- a/tests/DataTable/Columns/Relationships/RelationshipTest.php +++ b/tests/DataTable/Columns/Relationships/RelationshipTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class RelationshipTest extends \PHPUnit_Framework_TestCase { +class RelationshipTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -36,7 +36,7 @@ class RelationshipTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -50,11 +50,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testBuild() { $this->config->shouldReceive('getDataModel')->once()->andReturn(m::mock(array('method' => m::mock(array('getRelated' => m::mock(array('getTable' => ''))))))); diff --git a/tests/DataTable/DataTableTest.php b/tests/DataTable/DataTableTest.php index 3b1ff67e1..2b6d2b7d3 100644 --- a/tests/DataTable/DataTableTest.php +++ b/tests/DataTable/DataTableTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class DataTableTest extends \PHPUnit_Framework_TestCase { +class DataTableTest extends \PHPUnit\Framework\TestCase { /** * The Config mock @@ -36,7 +36,7 @@ class DataTableTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); $this->columnFactory = m::mock('Frozennode\Administrator\DataTable\Columns\Factory'); @@ -48,7 +48,7 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } @@ -119,10 +119,8 @@ public function testPrepareQuery() public function testPerformCountQuery() { - $result = new \stdClass; - $result->aggregate = 100; $countQuery = m::mock('Illuminate\Database\Query\Builder'); - $countQuery->shouldReceive('getConnection')->once()->andReturn(m::mock(array('select' => array($result)))); + $countQuery->shouldReceive('count')->once()->andReturn(100); $model = m::mock('Illuminate\Database\Eloquent\Model'); $model->shouldReceive('getKeyName')->once()->andReturn('id'); $this->config->shouldReceive('getDataModel')->once()->andReturn($model); @@ -130,6 +128,9 @@ public function testPerformCountQuery() $this->assertEquals($this->dataTable->performCountQuery($countQuery, 'foo', array(), 1), $output); } + /** + * @doesNotPerformAssertions + */ public function testSetFilters() { $query = m::mock('Illuminate\Database\Query\Builder'); diff --git a/tests/Fields/BoolTest.php b/tests/Fields/BoolTest.php index d95018c47..6d487dfb4 100644 --- a/tests/Fields/BoolTest.php +++ b/tests/Fields/BoolTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class BoolTest extends \PHPUnit_Framework_TestCase { +class BoolTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -36,7 +36,7 @@ class BoolTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -48,11 +48,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testBuild() { $this->validator->shouldReceive('arrayGet')->times(4); @@ -75,6 +78,9 @@ public function testFillModelFalse() $this->assertEquals($model->field, 0); } + /** + * @doesNotPerformAssertions + */ public function testSetFilter() { $this->validator->shouldReceive('arrayGet')->times(4); @@ -83,6 +89,9 @@ public function testSetFilter() $this->field->setFilter(null); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithValue() { $query = m::mock('Illuminate\Database\Query\Builder'); @@ -92,6 +101,9 @@ public function testFilterQueryWithValue() $this->field->filterQuery($query); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryNoValue() { $query = m::mock('Illuminate\Database\Query\Builder'); diff --git a/tests/Fields/EnumTest.php b/tests/Fields/EnumTest.php index bf8acfb33..af4399007 100644 --- a/tests/Fields/EnumTest.php +++ b/tests/Fields/EnumTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class EnumTest extends \PHPUnit_Framework_TestCase { +class EnumTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -36,7 +36,7 @@ class EnumTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -48,7 +48,7 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } @@ -61,6 +61,9 @@ public function testFillModel() $this->assertEquals($model->field, 1); } + /** + * @doesNotPerformAssertions + */ public function testSetFilter() { $this->validator->shouldReceive('arrayGet')->times(3); @@ -69,6 +72,9 @@ public function testSetFilter() $this->field->setFilter(null); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithValue() { $model = m::mock(array('getTable' => 'table')); @@ -79,6 +85,9 @@ public function testFilterQueryWithValue() $this->field->filterQuery($query); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithoutValue() { $model = m::mock(array('getTable' => 'table')); diff --git a/tests/Fields/FieldFactoryTest.php b/tests/Fields/FieldFactoryTest.php index 3b1a98999..686c46016 100644 --- a/tests/Fields/FieldFactoryTest.php +++ b/tests/Fields/FieldFactoryTest.php @@ -20,7 +20,7 @@ public function bar() {return 'not a relationship';} class FieldStub {} -class FieldFactoryTest extends \PHPUnit_Framework_TestCase { +class FieldFactoryTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -53,7 +53,7 @@ class FieldFactoryTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -64,7 +64,7 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } @@ -107,22 +107,18 @@ public function testValidateOptionsStringNameArrayOptions() $this->assertEquals($this->factory->validateOptions($name, $options), array('field_name' => $name)); } - /** - * @expectedException InvalidArgumentException - */ public function testValidateOptionsIntegerNameArrayOptions() { + $this->expectException(\InvalidArgumentException::class); $name = 0; $options = array(); $this->config->shouldReceive('getOption')->once()->andReturn(''); $this->factory->validateOptions($name, $options); } - /** - * @expectedException InvalidArgumentException - */ public function testValidateOptionsStringNameNonStringOptions() { + $this->expectException(\InvalidArgumentException::class); $name = 'field'; $options = true; $this->config->shouldReceive('getOption')->once()->andReturn(''); @@ -188,42 +184,34 @@ public function testCheckTypeExistsValidates() $this->assertEquals($options, array('type' => 'text')); } - /** - * @expectedException InvalidArgumentException - */ public function testCheckTypeExistsInvalidType() { + $this->expectException(\InvalidArgumentException::class); $options = array('type' => 'foo'); $this->config->shouldReceive('getOption')->once()->andReturn(''); $this->factory->checkTypeExists($options); } - /** - * @expectedException InvalidArgumentException - */ public function testCheckTypeExistsInvalidSettingsType() { + $this->expectException(\InvalidArgumentException::class); $options = array('type' => 'belongs_to_many'); $this->config->shouldReceive('getType')->once()->andReturn('settings') ->shouldReceive('getOption')->once()->andReturn(''); $this->factory->checkTypeExists($options); } - /** - * @expectedException InvalidArgumentException - */ public function testGetRelationshipKeyErrorOnMissingMethod() { + $this->expectException(\InvalidArgumentException::class); $this->config->shouldReceive('getDataModel')->once()->andReturn(new EloquentStub) ->shouldReceive('getOption')->once()->andReturn(''); $this->factory->getRelationshipKey('foo'); } - /** - * @expectedException InvalidArgumentException - */ public function testGetRelationshipKeyErrorOnMissingMethodObject() { + $this->expectException(\InvalidArgumentException::class); $this->config->shouldReceive('getDataModel')->once()->andReturn(new EloquentStub) ->shouldReceive('getOption')->once()->andReturn(''); $this->factory->getRelationshipKey('bar'); @@ -236,11 +224,9 @@ public function testGetRelationshipKeyValid() $this->assertEquals($this->factory->getRelationshipKey('btm'), 'belongs_to_many'); } - /** - * @expectedException InvalidArgumentException - */ public function testFindFieldMissingField() { + $this->expectException(\InvalidArgumentException::class); $this->factory->shouldReceive('getEditFields')->once()->andReturn(array()); $this->config->shouldReceive('getOption')->once()->andReturn(''); $this->factory->findField('foo'); @@ -252,11 +238,9 @@ public function testFindFieldFound() $this->assertEquals($this->factory->findField('foo'), 'bar'); } - /** - * @expectedException InvalidArgumentException - */ public function testFindFilterMissingField() { + $this->expectException(\InvalidArgumentException::class); $this->factory->shouldReceive('getFilters')->once()->andReturn(array()); $this->config->shouldReceive('getOption')->once()->andReturn(''); $this->factory->findFilter('foo'); @@ -426,6 +410,9 @@ public function testUpdateRelationshipsReturnsOptions() $this->assertEquals($this->factory->updateRelationshipOptions('field', 'filter', array(), array(), 'search'), array('foo' => 'bar')); } + /** + * @doesNotPerformAssertions + */ public function testFilterBySearchTermNoTerm() { $query = m::mock('Illuminate\Database\Eloquent\Builder'); @@ -434,6 +421,9 @@ public function testFilterBySearchTermNoTerm() $this->factory->filterBySearchTerm(null, $query, $field, array(), ''); } + /** + * @doesNotPerformAssertions + */ public function testFilterBySearchTermSelectedItems() { $query = m::mock('Illuminate\Database\Eloquent\Builder'); @@ -445,6 +435,9 @@ public function testFilterBySearchTermSelectedItems() $this->factory->filterBySearchTerm('foo', $query, $field, array(1), ''); } + /** + * @doesNotPerformAssertions + */ public function testFilterBySearchTermNoSelectedItems() { $query = m::mock('Illuminate\Database\Eloquent\Builder'); @@ -470,6 +463,9 @@ public function testFormatSelectedItemsEmpty() $this->assertEquals($this->factory->formatSelectedItems(false), array()); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryBySelectedItems() { $query = m::mock('Illuminate\Database\Eloquent\Builder'); @@ -480,6 +476,9 @@ public function testFilterQueryBySelectedItems() $this->factory->filterQueryBySelectedItems($query, array(), $field, ''); } + /** + * @doesNotPerformAssertions + */ public function testApplyConstraints() { $relatedModel = m::mock(array('getRelated' => null)); @@ -496,6 +495,9 @@ public function testApplyConstraints() $this->factory->applyConstraints(array('key' => array(1, 2)), $query, $field); } + /** + * @doesNotPerformAssertions + */ public function testApplyConstraintsEmpty() { $field = m::mock('Frozennode\Administrator\Fields\Field'); @@ -504,6 +506,9 @@ public function testApplyConstraintsEmpty() $this->factory->applyConstraints(array(), $query, $field); } + /** + * @doesNotPerformAssertions + */ public function testApplyConstraintsInvalidConstraintSupplied() { $field = m::mock('Frozennode\Administrator\Fields\Field'); diff --git a/tests/Fields/FieldTest.php b/tests/Fields/FieldTest.php index f1fb5a7f8..fc45142d0 100644 --- a/tests/Fields/FieldTest.php +++ b/tests/Fields/FieldTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class FieldTest extends \PHPUnit_Framework_TestCase { +class FieldTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -36,7 +36,7 @@ class FieldTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -48,17 +48,23 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testBuild() { $this->validator->shouldReceive('arrayGet')->times(3); $this->field->build(); } + /** + * @doesNotPerformAssertions + */ public function testBuildRunsVisibleCheck() { $this->validator->shouldReceive('arrayGet')->times(3)->andReturn(null, function($param) {}, null); @@ -66,6 +72,9 @@ public function testBuildRunsVisibleCheck() $this->field->build(); } + /** + * @doesNotPerformAssertions + */ public function testBuildRunsEditableCheck() { $this->validator->shouldReceive('arrayGet')->times(3)->andReturn(null, null, function($param) {}); @@ -73,6 +82,9 @@ public function testBuildRunsEditableCheck() $this->field->build(); } + /** + * @doesNotPerformAssertions + */ public function testValidates() { $this->field->shouldReceive('getRules')->once()->andReturn(array()); @@ -81,11 +93,9 @@ public function testValidates() $this->field->validateOptions(); } - /** - * @expectedException InvalidArgumentException - */ public function testValidateFails() { + $this->expectException(\InvalidArgumentException::class); $this->field->shouldReceive('getRules')->once()->andReturn(array()); $this->validator->shouldReceive('override')->once() ->shouldReceive('fails')->once()->andReturn(true) @@ -110,6 +120,9 @@ public function testFillModelNotNullInput() $this->assertEquals($model->field, 'test'); } + /** + * @doesNotPerformAssertions + */ public function testSetFilter() { $this->validator->shouldReceive('arrayGet')->times(3); @@ -118,6 +131,9 @@ public function testSetFilter() $this->field->setFilter(null); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithMinAndMax() { $model = m::mock(array('getTable' => 'table')); @@ -128,6 +144,9 @@ public function testFilterQueryWithMinAndMax() $this->field->filterQuery($query); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryOnlyMin() { $model = m::mock(array('getTable' => 'table')); @@ -138,6 +157,9 @@ public function testFilterQueryOnlyMin() $this->field->filterQuery($query); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryOnlyMax() { $model = m::mock(array('getTable' => 'table')); @@ -148,6 +170,9 @@ public function testFilterQueryOnlyMax() $this->field->filterQuery($query); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryNoMinOrMax() { $model = m::mock(array('getTable' => 'table')); @@ -183,11 +208,9 @@ public function testGetOptionSucceeds() $this->assertEquals($this->field->getOption('foo'), 'bar'); } - /** - * @expectedException InvalidArgumentException - */ public function testGetOptionFails() { + $this->expectException(\InvalidArgumentException::class); $this->field->shouldReceive('getOptions')->once()->andReturn(array('field_name' => 'bar')); $this->field->getOption('foo'); } diff --git a/tests/Fields/FileTest.php b/tests/Fields/FileTest.php index 4cc8dffa8..de7baf0e0 100644 --- a/tests/Fields/FileTest.php +++ b/tests/Fields/FileTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class FileTest extends \PHPUnit_Framework_TestCase { +class FileTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -36,7 +36,7 @@ class FileTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -48,11 +48,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testBuild() { $url = m::mock('Illuminate\Routing\UrlGenerator'); diff --git a/tests/Fields/KeyTest.php b/tests/Fields/KeyTest.php index a35151c5b..fc3088134 100644 --- a/tests/Fields/KeyTest.php +++ b/tests/Fields/KeyTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class KeyTest extends \PHPUnit_Framework_TestCase { +class KeyTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -36,7 +36,7 @@ class KeyTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -48,11 +48,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithValue() { $model = m::mock(array('getTable' => 'table')); @@ -63,6 +66,9 @@ public function testFilterQueryWithValue() $this->field->filterQuery($query); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithoutValue() { $model = m::mock(array('getTable' => 'table')); diff --git a/tests/Fields/NumberTest.php b/tests/Fields/NumberTest.php index 79dfbcb2b..9afd8d8c2 100644 --- a/tests/Fields/NumberTest.php +++ b/tests/Fields/NumberTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class NumberTest extends \PHPUnit_Framework_TestCase { +class NumberTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -36,7 +36,7 @@ class NumberTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -48,11 +48,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testSetFilter() { $this->validator->shouldReceive('arrayGet')->times(3); diff --git a/tests/Fields/Relationships/BelongsToManyTest.php b/tests/Fields/Relationships/BelongsToManyTest.php index def674536..eaf2dd444 100644 --- a/tests/Fields/Relationships/BelongsToManyTest.php +++ b/tests/Fields/Relationships/BelongsToManyTest.php @@ -20,7 +20,7 @@ public function fieldNoSort() { public function __unset($rel) {unset($this->{$rel});} } -class BelongsToManyTest extends \PHPUnit_Framework_TestCase { +class BelongsToManyTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -53,7 +53,7 @@ class BelongsToManyTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -66,16 +66,19 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testBuild() { $relatedModel = m::mock(array('getKeyName' => 'id', 'getTable' => 'other_table')); $relationship = m::mock(array('getRelated' => $relatedModel, 'getForeignKeyName' => 'some_id', 'getQualifiedRelatedPivotKeyName' => 'some_other_id', - 'getTable' => 'table')); + 'getTable' => 'table', 'getQualifiedForeignPivotKeyName' => 'qualified_foreign_pivot_key_name')); $model = m::mock(array('field' => $relationship, 'getTable' => 'table')); $this->config->shouldReceive('getDataModel')->twice()->andReturn($model); $this->validator->shouldReceive('arrayGet')->times(6); @@ -100,15 +103,18 @@ public function testFillModelWithoutSortField() $this->assertTrue(!isset($model->rel)); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithValueNotJoined() { $connection = m::mock('Illuminate\Database\Connection'); - $connection->shouldReceive('getTablePrefix')->once()->andReturn(''); + $connection->shouldReceive('getTablePrefix')->once()->never(); $query = m::mock('Illuminate\Database\Query\Builder'); $query->shouldReceive('whereIn')->once() ->shouldReceive('join')->once() - ->shouldReceive('havingRaw')->once() - ->shouldReceive('getConnection')->once()->andReturn($connection); + ->shouldReceive('havingRaw')->never() + ->shouldReceive('getConnection')->never(); $this->validator->shouldReceive('isJoined')->once()->andReturn(false); $model = m::mock(array('getTable' => 'table', 'getKeyName' => 'id')); $this->config->shouldReceive('getDataModel')->twice()->andReturn($model); @@ -117,15 +123,18 @@ public function testFilterQueryWithValueNotJoined() $this->field->filterQuery($query, $selects); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithValueAlreadyJoined() { $connection = m::mock('Illuminate\Database\Connection'); - $connection->shouldReceive('getTablePrefix')->once()->andReturn(''); + $connection->shouldReceive('getTablePrefix')->once()->never(); $query = m::mock('Illuminate\Database\Query\Builder'); $query->shouldReceive('whereIn')->once() ->shouldReceive('join')->never() - ->shouldReceive('havingRaw')->once() - ->shouldReceive('getConnection')->once()->andReturn($connection); + ->shouldReceive('havingRaw')->never() + ->shouldReceive('getConnection')->never(); $this->validator->shouldReceive('isJoined')->once()->andReturn(true); $model = m::mock(array('getTable' => 'table', 'getKeyName' => 'id')); $this->config->shouldReceive('getDataModel')->twice()->andReturn($model); @@ -134,6 +143,9 @@ public function testFilterQueryWithValueAlreadyJoined() $this->field->filterQuery($query, $selects); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithoutValue() { $query = m::mock('Illuminate\Database\Query\Builder'); @@ -147,6 +159,9 @@ public function testFilterQueryWithoutValue() $this->field->filterQuery($query, $selects); } + /** + * @doesNotPerformAssertions + */ public function testConstrainQueryNotJoined() { $query = m::mock('Illuminate\Database\Eloquent\Builder'); @@ -158,6 +173,9 @@ public function testConstrainQueryNotJoined() $this->field->constrainQuery($query, $model, 'foo'); } + /** + * @doesNotPerformAssertions + */ public function testConstrainQueryAlreadyJoined() { $query = m::mock('Illuminate\Database\Eloquent\Builder'); diff --git a/tests/Fields/Relationships/BelongsToTest.php b/tests/Fields/Relationships/BelongsToTest.php index f9e2a947e..c02446064 100644 --- a/tests/Fields/Relationships/BelongsToTest.php +++ b/tests/Fields/Relationships/BelongsToTest.php @@ -8,7 +8,7 @@ class BelongsToEloquentStub { public function __unset($rel) {unset($this->{$rel});} } -class BelongsToTest extends \PHPUnit_Framework_TestCase { +class BelongsToTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -41,7 +41,7 @@ class BelongsToTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -54,11 +54,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testBuild() { $relatedModel = m::mock(array('getTable' => 'table', 'getKeyName' => 'id')); @@ -91,6 +94,9 @@ public function testFillModelWithoutInput() $this->assertTrue(!isset($model->rel)); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithValue() { $query = m::mock('Illuminate\Database\Query\Builder'); @@ -100,6 +106,9 @@ public function testFilterQueryWithValue() $this->field->filterQuery($query); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithoutValue() { $query = m::mock('Illuminate\Database\Query\Builder'); diff --git a/tests/Fields/Relationships/HasOneOrManyTest.php b/tests/Fields/Relationships/HasOneOrManyTest.php index fdba8f92f..69561811d 100644 --- a/tests/Fields/Relationships/HasOneOrManyTest.php +++ b/tests/Fields/Relationships/HasOneOrManyTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class HasOneOrManyTest extends \PHPUnit_Framework_TestCase { +class HasOneOrManyTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -36,7 +36,7 @@ class HasOneOrManyTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -49,11 +49,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testBuild() { $relatedModel = m::mock(array('getKeyName' => 'id', 'getTable' => 'other_table')); @@ -66,6 +69,9 @@ public function testBuild() $this->field->build(); } + /** + * @doesNotPerformAssertions + */ public function testConstrainQuery() { $query = m::mock('Illuminate\Database\Eloquent\Builder'); diff --git a/tests/Fields/Relationships/RelationshipTest.php b/tests/Fields/Relationships/RelationshipTest.php index 263250ba5..550ca1243 100644 --- a/tests/Fields/Relationships/RelationshipTest.php +++ b/tests/Fields/Relationships/RelationshipTest.php @@ -8,7 +8,7 @@ public function foo() {} public function bar() {} } -class RelationshipTest extends \PHPUnit_Framework_TestCase { +class RelationshipTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -41,7 +41,7 @@ class RelationshipTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -54,11 +54,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testBuild() { $relationship = m::mock(array('getRelated' => m::mock(array('getTable' => 'table')))); diff --git a/tests/Fields/TextTest.php b/tests/Fields/TextTest.php index e335ae5a4..b574d9491 100644 --- a/tests/Fields/TextTest.php +++ b/tests/Fields/TextTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class TextTest extends \PHPUnit_Framework_TestCase { +class TextTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -36,7 +36,7 @@ class TextTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -48,11 +48,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithValue() { $query = m::mock('Illuminate\Database\Query\Builder'); @@ -62,6 +65,9 @@ public function testFilterQueryWithValue() $this->field->filterQuery($query); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithoutValue() { $query = m::mock('Illuminate\Database\Query\Builder'); diff --git a/tests/Fields/TimeTest.php b/tests/Fields/TimeTest.php index b6a67f184..db54958f4 100644 --- a/tests/Fields/TimeTest.php +++ b/tests/Fields/TimeTest.php @@ -3,7 +3,7 @@ use Mockery as m; -class TimeTest extends \PHPUnit_Framework_TestCase { +class TimeTest extends \PHPUnit\Framework\TestCase { /** * The Validator mock @@ -36,7 +36,7 @@ class TimeTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->validator = m::mock('Frozennode\Administrator\Validator'); $this->config = m::mock('Frozennode\Administrator\Config\Model\Config'); @@ -48,11 +48,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryWithMinAndMax() { $model = m::mock(array('getTable' => 'table')); @@ -64,6 +67,9 @@ public function testFilterQueryWithMinAndMax() $this->field->filterQuery($query); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryOnlyMin() { $model = m::mock(array('getTable' => 'table')); @@ -75,6 +81,9 @@ public function testFilterQueryOnlyMin() $this->field->filterQuery($query); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryOnlyMax() { $model = m::mock(array('getTable' => 'table')); @@ -86,6 +95,9 @@ public function testFilterQueryOnlyMax() $this->field->filterQuery($query); } + /** + * @doesNotPerformAssertions + */ public function testFilterQueryNoMinOrMax() { $model = m::mock(array('getTable' => 'table')); diff --git a/tests/MenuTest.php b/tests/MenuTest.php index 07b670497..7a5367a69 100644 --- a/tests/MenuTest.php +++ b/tests/MenuTest.php @@ -1,9 +1,10 @@ config = m::mock('Illuminate\Config\Repository'); $this->configFactory = m::mock('Frozennode\Administrator\Config\Factory'); @@ -39,7 +40,7 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } @@ -49,7 +50,10 @@ public function testGetMenuSimpleReturnWithPermission() $this->config->shouldReceive('get')->once()->andReturn(array('test_name')); $itemconfig = m::mock('Frozennode\Administrator\Config\Config'); $itemconfig->shouldReceive('getOption')->twice()->andReturn(true, 'test_title'); - $this->configFactory->shouldReceive('make')->once()->andReturn($itemconfig); + $this->configFactory->shouldReceive('make')->once()->andReturn($itemconfig) + ->shouldReceive('getSettingsPrefix')->once()->andReturn('settings.') + ->shouldReceive('getPagePrefix')->once()->andReturn('page.'); + URL::shouldReceive('route')->with('admin_index', array('test_name'))->andReturn('test_name'); $this->assertEquals($this->menu->getMenu(), array('test_name' => 'test_title')); } @@ -67,7 +71,9 @@ public function testGetMenuNested() $this->config->shouldReceive('get')->once()->andReturn(array('Header' => array('test_name'))); $itemconfig = m::mock('Frozennode\Administrator\Config\Config'); $itemconfig->shouldReceive('getOption')->twice()->andReturn(true, 'test_title'); - $this->configFactory->shouldReceive('make')->once()->andReturn($itemconfig); + $this->configFactory->shouldReceive('make')->once()->andReturn($itemconfig) + ->shouldReceive('getSettingsPrefix')->once()->andReturn('settings.') + ->shouldReceive('getPagePrefix')->once()->andReturn('page.'); $this->assertEquals($this->menu->getMenu(), array('Header' => array('test_name' => 'test_title'))); } @@ -85,7 +91,9 @@ public function testGetMenuDeepNested() $this->config->shouldReceive('get')->once()->andReturn(array('Header' => array('Header2' => array('test_name')))); $itemconfig = m::mock('Frozennode\Administrator\Config\Config'); $itemconfig->shouldReceive('getOption')->twice()->andReturn(true, 'test_title'); - $this->configFactory->shouldReceive('make')->once()->andReturn($itemconfig); + $this->configFactory->shouldReceive('make')->once()->andReturn($itemconfig) + ->shouldReceive('getSettingsPrefix')->once()->andReturn('settings.') + ->shouldReceive('getPagePrefix')->once()->andReturn('page.'); $this->assertEquals($this->menu->getMenu(), array('Header' => array('Header2' => array('test_name' => 'test_title')))); } diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index 500a10c5d..b8dc8788e 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -5,7 +5,7 @@ class EloquentStub extends \Illuminate\Database\Eloquent\Model {} -class ValidatorTest extends \PHPUnit_Framework_TestCase { +class ValidatorTest extends \PHPUnit\Framework\TestCase { /** * The UrlGenerator mock @@ -24,7 +24,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase { /** * Set up function */ - public function setUp() + public function setUp(): void { $this->url = m::mock('Illuminate\Routing\UrlGenerator'); $this->validator = m::mock('Frozennode\Administrator\Validator')->makePartial(); @@ -33,11 +33,14 @@ public function setUp() /** * Tear down function */ - public function tearDown() + public function tearDown(): void { m::close(); } + /** + * @doesNotPerformAssertions + */ public function testOverrideSetsDataRulesAndMessages() { $this->validator->shouldReceive('setData')->once()