Skip to content

Commit 85b94a8

Browse files
Merge pull request #4 from robertpustulka/cake-4
CakePHP 4 support
2 parents a7060ab + 405eb54 commit 85b94a8

File tree

6 files changed

+40
-30
lines changed

6 files changed

+40
-30
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ language: php
22
dist: trusty
33

44
php:
5-
- 5.6
6-
- 7.0
7-
- 7.1
85
- 7.2
6+
- 7.3
7+
- 7.4
8+
- 8.0
99

1010
sudo: false
1111

@@ -17,9 +17,9 @@ env:
1717

1818
matrix:
1919
include:
20-
- php: 7.1
20+
- php: 7.2
2121
env: PHPCS=1 DEFAULT=0
22-
- php: 7.1
22+
- php: 7.2
2323
env: COVERALLS=1 DEFAULT=0 DB=mysql db_dsn='mysql://[email protected]/searchable_test'
2424

2525
before_script:

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## :package: [3.0.0](https://packagist.org/packages/chris48s/cakephp-searchable#3.0.0) - TODO
4+
5+
* Adds compatibility with CakePHP 4, drops compatibility with CakePHP 3
6+
* New maintainer: @robertpustulka
7+
38
## :package: [2.0.0](https://packagist.org/packages/chris48s/cakephp-searchable#2.0.0) - 2018-05-10
49

510
* Remove deprecated CakePHP calls

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
}
1313
],
1414
"require": {
15-
"cakephp/cakephp": "^3.5",
15+
"cakephp/cakephp": "4.*",
1616
"php": ">=5.6"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "^5.7",
2019
"cakephp/cakephp-codesniffer": "dev-master",
21-
"php-coveralls/php-coveralls": "^2.0.0"
20+
"php-coveralls/php-coveralls": "^2.0.0",
21+
"phpunit/phpunit": "8.*"
2222
},
2323
"autoload": {
2424
"psr-4": {

src/Model/Behavior/SearchableBehavior.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class SearchableBehavior extends Behavior
2727
* @throws SearchableFatalException If database engine is not MySQL
2828
* @return void
2929
*/
30-
public function initialize(array $config)
30+
public function initialize(array $config): void
3131
{
3232
$connection = $this->_table->getConnection();
3333

@@ -58,7 +58,7 @@ public function initialize(array $config)
5858
* @throws SearchableException If columns are invalid
5959
* @return \Cake\ORM\Query
6060
*/
61-
public function findMatches(Query $query, array $options)
61+
public function findMatches(Query $query, array $options): Query
6262
{
6363
$conditions = [];
6464
$options = array_values($options);
@@ -98,7 +98,7 @@ public function findMatches(Query $query, array $options)
9898
* @throws SearchableException If columns are invalid
9999
* @return bool
100100
*/
101-
private function _validateColumns($columnList)
101+
private function _validateColumns(string $columnList): bool
102102
{
103103
$columns = explode(',', $columnList);
104104
foreach ($columns as $column) {

tests/TestCase/Model/Behavior/SearchableBehaviorTest.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,26 @@
33
namespace Chris48s\Searchable\Test\TestCase\Model\Behavior;
44

55
use Cake\Datasource\ConnectionManager;
6-
use Cake\ORM\TableRegistry;
76
use Cake\TestSuite\TestCase;
87
use Chris48s\Searchable\Exception\SearchableException;
98
use Chris48s\Searchable\Exception\SearchableFatalException;
10-
use Chris48s\Searchable\Model\Behavior\SearchableBehavior;
119

1210
class SearchableBehaviorTest extends TestCase
1311
{
1412
public $fixtures = [
15-
'plugin.Chris48s\Searchable.foo'
13+
'plugin.Chris48s\Searchable.Foo'
1614
];
1715

18-
public function tearDown()
16+
public function tearDown(): void
1917
{
2018
parent::tearDown();
21-
TableRegistry::clear();
19+
$this->getTableLocator()->clear();
2220
}
2321

2422
// set up a table to use for testing
2523
private function getTable()
2624
{
27-
$table = TableRegistry::get('Foo');
25+
$table = $this->getTableLocator()->get('Foo');
2826
$table->addBehavior('Chris48s/Searchable.Searchable');
2927

3028
return $table;
@@ -34,7 +32,7 @@ private function getTable()
3432
and ensure SearchableException is thrown */
3533
public function testNonStringColumn()
3634
{
37-
$this->setExpectedException('Chris48s\Searchable\Exception\SearchableException');
35+
$this->expectException(SearchableException::class);
3836
$table = $this->getTable();
3937
$table->find('matches', [
4038
[
@@ -48,7 +46,7 @@ public function testNonStringColumn()
4846
and ensure SearchableException is thrown */
4947
public function testInvalidColumn()
5048
{
51-
$this->setExpectedException('Chris48s\Searchable\Exception\SearchableException');
49+
$this->expectException(SearchableException::class);
5250
$table = $this->getTable();
5351
$table->find('matches', [
5452
[
@@ -77,7 +75,7 @@ public function testInvalidMode()
7775
// omit 'match' key and ensure SearchableException is thrown
7876
public function testMissingMatchKey()
7977
{
80-
$this->setExpectedException('Chris48s\Searchable\Exception\SearchableException');
78+
$this->expectException(SearchableException::class);
8179
$table = $this->getTable();
8280
$table->find('matches', [
8381
[
@@ -89,7 +87,7 @@ public function testMissingMatchKey()
8987
// omit 'against' key and ensure SearchableException is thrown
9088
public function testMissingAgainstKey()
9189
{
92-
$this->setExpectedException('Chris48s\Searchable\Exception\SearchableException');
90+
$this->expectException(SearchableException::class);
9391
$table = $this->getTable();
9492
$table->find('matches', [
9593
[
@@ -103,7 +101,7 @@ public function testMissingAgainstKey()
103101
and ensure correct exception is thrown */
104102
public function testInvalidDB()
105103
{
106-
$this->setExpectedException('Chris48s\Searchable\Exception\SearchableFatalException');
104+
$this->expectException(SearchableFatalException::class);
107105

108106
//set up a SQLite DB connection - SQLite is not supported
109107
ConnectionManager::setConfig('invalid', [
@@ -118,7 +116,7 @@ public function testInvalidDB()
118116
`textcol` VARCHAR(255),
119117
PRIMARY KEY (`id`)
120118
);");
121-
$table = TableRegistry::get('Foo', ['connection' => $conn]);
119+
$table = $this->getTableLocator()->get('Foo', ['connection' => $conn]);
122120
$table->addBehavior('Chris48s/Searchable.Searchable');
123121

124122
//tidy up

tests/bootstrap.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php
2+
3+
use Cake\Cache\Cache;
4+
use Cake\Core\BasePlugin;
5+
use Cake\Core\Configure;
6+
use Cake\Core\Plugin;
7+
use Cake\Datasource\ConnectionManager;
8+
use Cake\Filesystem\Folder;
29
// @codingStandardsIgnoreFile
310

411
$findRoot = function () {
@@ -38,10 +45,10 @@
3845
require ROOT . '/vendor/autoload.php';
3946
require CORE_PATH . 'config/bootstrap.php';
4047

41-
Cake\Core\Configure::write('App', ['namespace' => 'App']);
42-
Cake\Core\Configure::write('debug', true);
48+
Configure::write('App', ['namespace' => 'App']);
49+
Configure::write('debug', true);
4350

44-
$TMP = new \Cake\Filesystem\Folder(TMP);
51+
$TMP = new Folder(TMP);
4552
$TMP->create(TMP . 'cache/models', 0777);
4653
$TMP->create(TMP . 'cache/persistent', 0777);
4754
$TMP->create(TMP . 'cache/views', 0777);
@@ -66,19 +73,19 @@
6673
]
6774
];
6875

69-
Cake\Cache\Cache::setConfig($cache);
70-
Cake\Core\Configure::write('Session', [
76+
Cache::setConfig($cache);
77+
Configure::write('Session', [
7178
'defaults' => 'php'
7279
]);
7380

74-
Cake\Core\Plugin::load('Chris48s/Searchable', ['path' => ROOT . DS, 'autoload' => true]);
81+
Plugin::getCollection()->add(new BasePlugin(['name' => 'Chris48s/Searchable', 'path' => ROOT . DS, 'autoload' => true]));
7582

7683
// Ensure default test connection is defined
7784
if (!getenv('db_dsn')) {
7885
putenv('db_dsn=sqlite:///:memory:');
7986
}
8087

81-
Cake\Datasource\ConnectionManager::setConfig('test', [
88+
ConnectionManager::setConfig('test', [
8289
'url' => getenv('db_dsn'),
8390
'timezone' => 'UTC'
8491
]);

0 commit comments

Comments
 (0)