Browse Source

Merge pull request #12951 from cakephp/4.x-stub2

4.x stub2
Mark Story 7 years ago
parent
commit
c96b280700

+ 1 - 2
composer.json

@@ -73,8 +73,7 @@
             "TestPluginTwo\\": "tests/test_app/Plugin/TestPluginTwo/src/",
             "Company\\TestPluginThree\\": "tests/test_app/Plugin/Company/TestPluginThree/src/",
             "Company\\TestPluginThree\\Test\\": "tests/test_app/Plugin/Company/TestPluginThree/tests/",
-            "ParentPlugin\\": "tests/test_app/Plugin/ParentPlugin/src/",
-            "PluginJs\\": "tests/test_app/Plugin/PluginJs/src/"
+            "ParentPlugin\\": "tests/test_app/Plugin/ParentPlugin/src/"
         }
     },
     "replace": {

+ 7 - 13
tests/TestCase/Error/DebuggerTest.php

@@ -20,13 +20,7 @@ use Cake\Core\Configure;
 use Cake\Error\Debugger;
 use Cake\Log\Log;
 use Cake\TestSuite\TestCase;
-
-/**
- * DebuggerTestCaseDebugger class
- */
-class DebuggerTestCaseDebugger extends Debugger
-{
-}
+use TestApp\Error\TestDebugger;
 
 class DebuggableThing
 {
@@ -572,16 +566,16 @@ TEXT;
     public function testGetInstance()
     {
         $result = Debugger::getInstance();
-        $this->assertInstanceOf('Cake\Error\Debugger', $result);
+        $this->assertInstanceOf(Debugger::class, $result);
 
-        $result = Debugger::getInstance(__NAMESPACE__ . '\DebuggerTestCaseDebugger');
-        $this->assertInstanceOf(__NAMESPACE__ . '\DebuggerTestCaseDebugger', $result);
+        $result = Debugger::getInstance(TestDebugger::class);
+        $this->assertInstanceOf(TestDebugger::class, $result);
 
         $result = Debugger::getInstance();
-        $this->assertInstanceOf(__NAMESPACE__ . '\DebuggerTestCaseDebugger', $result);
+        $this->assertInstanceOf(TestDebugger::class, $result);
 
-        $result = Debugger::getInstance('Cake\Error\Debugger');
-        $this->assertInstanceOf('Cake\Error\Debugger', $result);
+        $result = Debugger::getInstance(Debugger::class);
+        $this->assertInstanceOf(Debugger::class, $result);
     }
 
     /**

+ 8 - 34
tests/TestCase/Error/ErrorHandlerTest.php

@@ -25,39 +25,8 @@ use Cake\Log\Log;
 use Cake\Routing\Exception\MissingControllerException;
 use Cake\Routing\Router;
 use Cake\TestSuite\TestCase;
-
-/**
- * Testing stub.
- */
-class TestErrorHandler extends ErrorHandler
-{
-    /**
-     * Access the response used.
-     *
-     * @var \Cake\Http\Response
-     */
-    public $response;
-
-    /**
-     * Stub output clearing in tests.
-     *
-     * @return void
-     */
-    protected function _clearOutput(): void
-    {
-        // noop
-    }
-
-    /**
-     * Stub sending responses
-     *
-     * @return void
-     */
-    protected function _sendResponse($response): void
-    {
-        $this->response = $response;
-    }
-}
+use Psr\Log\LoggerInterface;
+use TestApp\Error\TestErrorHandler;
 
 /**
  * ErrorHandlerTest class
@@ -67,6 +36,11 @@ class ErrorHandlerTest extends TestCase
     protected $_restoreError = false;
 
     /**
+     * @var \Psr\Log\LoggerInterface|\PHPUnit\Framework\MockObject\MockObject
+     */
+    protected $_logger;
+
+    /**
      * error level property
      *
      */
@@ -92,7 +66,7 @@ class ErrorHandlerTest extends TestCase
         Router::setRequestInfo($request);
         Configure::write('debug', true);
 
-        $this->_logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
+        $this->_logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
 
         Log::reset();
         Log::setConfig('error_test', [

+ 15 - 80
tests/TestCase/Http/Client/Adapter/StreamTest.php

@@ -18,100 +18,34 @@ use Cake\Http\Client\Adapter\Stream;
 use Cake\Http\Client\Request;
 use Cake\Http\Client\Response;
 use Cake\TestSuite\TestCase;
-
-/**
- * CakeStreamWrapper class
- */
-class CakeStreamWrapper implements \ArrayAccess
-{
-    private $_stream;
-
-    private $_query = [];
-
-    private $_data = [
-        'headers' => [
-            'HTTP/1.1 200 OK',
-        ],
-    ];
-
-    public function stream_open($path, $mode, $options, &$openedPath)
-    {
-        if ($path === 'http://throw_exception/') {
-            throw new \Exception();
-        }
-
-        $query = parse_url($path, PHP_URL_QUERY);
-        if ($query) {
-            parse_str($query, $this->_query);
-        }
-
-        $this->_stream = fopen('php://memory', 'rb+');
-        fwrite($this->_stream, str_repeat('x', 20000));
-        rewind($this->_stream);
-
-        return true;
-    }
-
-    public function stream_close()
-    {
-        return fclose($this->_stream);
-    }
-
-    public function stream_read($count)
-    {
-        if (isset($this->_query['sleep'])) {
-            sleep(1);
-        }
-
-        return fread($this->_stream, $count);
-    }
-
-    public function stream_eof()
-    {
-        return feof($this->_stream);
-    }
-
-    public function stream_set_option($option, $arg1, $arg2)
-    {
-        return false;
-    }
-
-    public function offsetExists($offset)
-    {
-        return isset($this->_data[$offset]);
-    }
-
-    public function offsetGet($offset)
-    {
-        return $this->_data[$offset];
-    }
-
-    public function offsetSet($offset, $value)
-    {
-        $this->_data[$offset] = $value;
-    }
-
-    public function offsetUnset($offset)
-    {
-        unset($this->_data[$offset]);
-    }
-}
+use TestApp\Http\Client\Adapter\CakeStreamWrapper;
 
 /**
  * HTTP stream adapter test.
  */
 class StreamTest extends TestCase
 {
+    /**
+     * @var \Cake\Http\Client\Adapter\Stream|\PHPUnit\Framework\MockObject\MockObject
+     */
+    protected $stream;
+
+    /**
+     * @return void
+     */
     public function setUp()
     {
         parent::setUp();
-        $this->stream = $this->getMockBuilder('Cake\Http\Client\Adapter\Stream')
+        $this->stream = $this->getMockBuilder(Stream::class)
             ->setMethods(['_send'])
             ->getMock();
         stream_wrapper_unregister('http');
-        stream_wrapper_register('http', __NAMESPACE__ . '\CakeStreamWrapper');
+        stream_wrapper_register('http', CakeStreamWrapper::class);
     }
 
+    /**
+     * @return void
+     */
     public function tearDown()
     {
         parent::tearDown();
@@ -403,6 +337,7 @@ class StreamTest extends TestCase
         ];
         $content = 'This is the third page';
 
+        /** @var \Cake\Http\Client\Response[] $responses */
         $responses = $this->stream->createResponses($headers, $content);
         $this->assertCount(3, $responses);
         $this->assertEquals('close', $responses[0]->getHeaderLine('Connection'));

+ 31 - 20
tests/TestCase/ORM/Association/BelongsToManyTest.php

@@ -15,6 +15,7 @@ declare(strict_types=1);
  */
 namespace Cake\Test\TestCase\ORM\Association;
 
+use Cake\Database\Connection;
 use Cake\Database\Expression\QueryExpression;
 use Cake\Datasource\ConnectionManager;
 use Cake\Event\EventInterface;
@@ -22,6 +23,8 @@ use Cake\ORM\Association\BelongsTo;
 use Cake\ORM\Association\BelongsToMany;
 use Cake\ORM\Association\HasMany;
 use Cake\ORM\Entity;
+use Cake\ORM\Query;
+use Cake\ORM\RulesChecker;
 use Cake\ORM\Table;
 use Cake\TestSuite\TestCase;
 
@@ -187,7 +190,7 @@ class BelongsToManyTest extends TestCase
      */
     public function testJunctionConnection()
     {
-        $mock = $this->getMockBuilder('Cake\Database\Connection')
+        $mock = $this->getMockBuilder(Connection::class)
                 ->setMethods(['setDriver'])
                 ->setConstructorArgs([['name' => 'other_source']])
                 ->getMock();
@@ -547,7 +550,7 @@ class BelongsToManyTest extends TestCase
 
         $joint->expects($this->at(1))
             ->method('save')
-            ->will($this->returnCallback(function ($e, $opts) use ($entity) {
+            ->will($this->returnCallback(function (Entity $e, $opts) use ($entity) {
                 $expected = ['article_id' => 1, 'tag_id' => 2];
                 $this->assertEquals($expected, $e->toArray());
                 $this->assertEquals(['foo' => 'bar'], $opts);
@@ -558,7 +561,7 @@ class BelongsToManyTest extends TestCase
 
         $joint->expects($this->at(2))
             ->method('save')
-            ->will($this->returnCallback(function ($e, $opts) use ($entity) {
+            ->will($this->returnCallback(function (Entity $e, $opts) use ($entity) {
                 $expected = ['article_id' => 1, 'tag_id' => 3];
                 $this->assertEquals($expected, $e->toArray());
                 $this->assertEquals(['foo' => 'bar'], $opts);
@@ -579,6 +582,7 @@ class BelongsToManyTest extends TestCase
     public function testLinkSetSourceToJunctionEntities()
     {
         $connection = ConnectionManager::get('test');
+        /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $joint */
         $joint = $this->getMockBuilder(Table::class)
             ->setMethods(['save', 'getPrimaryKey'])
             ->setConstructorArgs([['alias' => 'ArticlesTags', 'connection' => $connection]])
@@ -884,7 +888,7 @@ class BelongsToManyTest extends TestCase
     {
         $articles = $this->getTableLocator()->get('Articles');
         $tags = $this->getTableLocator()->get('Tags');
-        $tags->getEventManager()->on('Model.buildRules', function (EventInterface $event, $rules) {
+        $tags->getEventManager()->on('Model.buildRules', function (EventInterface $event, RulesChecker $rules) {
             $rules->add(function () {
                 return false;
             }, 'rule', ['errorField' => 'name', 'message' => 'Bad data']);
@@ -934,11 +938,13 @@ class BelongsToManyTest extends TestCase
      */
     public function testSaveAssociatedEmptySetSuccess($value)
     {
+        /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockBuilder $table */
         $table = $this->getMockBuilder(Table::class)
             ->setMethods(['table'])
             ->getMock();
         $table->setSchema([]);
-        $assoc = $this->getMockBuilder('Cake\ORM\Association\BelongsToMany')
+        /** @var \Cake\ORM\Association\BelongsToMany|\PHPUnit\Framework\MockObject\MockObject $assoc */
+        $assoc = $this->getMockBuilder(BelongsToMany::class)
             ->setMethods(['_saveTarget', 'replaceLinks'])
             ->setConstructorArgs(['tags', ['sourceTable' => $table]])
             ->getMock();
@@ -963,11 +969,13 @@ class BelongsToManyTest extends TestCase
      */
     public function testSaveAssociatedEmptySetUpdateSuccess($value)
     {
+        /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockBuilder $table */
         $table = $this->getMockBuilder(Table::class)
             ->setMethods(['table'])
             ->getMock();
         $table->setSchema([]);
-        $assoc = $this->getMockBuilder('Cake\ORM\Association\BelongsToMany')
+        /** @var \Cake\ORM\Association\BelongsToMany|\PHPUnit\Framework\MockObject\MockObject $assoc */
+        $assoc = $this->getMockBuilder(BelongsToMany::class)
             ->setMethods(['_saveTarget', 'replaceLinks'])
             ->setConstructorArgs(['tags', ['sourceTable' => $table]])
             ->getMock();
@@ -995,11 +1003,12 @@ class BelongsToManyTest extends TestCase
      */
     public function testSaveAssociatedWithReplace()
     {
+        /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */
         $table = $this->getMockBuilder(Table::class)
             ->setMethods(['table'])
             ->getMock();
         $table->setSchema([]);
-        $assoc = $this->getMockBuilder('Cake\ORM\Association\BelongsToMany')
+        $assoc = $this->getMockBuilder(BelongsToMany::class)
             ->setMethods(['replaceLinks'])
             ->setConstructorArgs(['tags', ['sourceTable' => $table]])
             ->getMock();
@@ -1025,11 +1034,12 @@ class BelongsToManyTest extends TestCase
      */
     public function testSaveAssociatedWithReplaceReturnFalse()
     {
+        /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */
         $table = $this->getMockBuilder(Table::class)
             ->setMethods(['table'])
             ->getMock();
         $table->setSchema([]);
-        $assoc = $this->getMockBuilder('Cake\ORM\Association\BelongsToMany')
+        $assoc = $this->getMockBuilder(BelongsToMany::class)
             ->setMethods(['replaceLinks'])
             ->setConstructorArgs(['tags', ['sourceTable' => $table]])
             ->getMock();
@@ -1056,15 +1066,16 @@ class BelongsToManyTest extends TestCase
     public function testSaveAssociatedOnlyEntitiesAppend()
     {
         $connection = ConnectionManager::get('test');
-        $mock = $this->getMockBuilder(Table::class)
+        /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */
+        $table = $this->getMockBuilder(Table::class)
             ->setMethods(['saveAssociated', 'schema'])
             ->setConstructorArgs([['table' => 'tags', 'connection' => $connection]])
             ->getMock();
-        $mock->setPrimaryKey('id');
+        $table->setPrimaryKey('id');
 
         $config = [
             'sourceTable' => $this->article,
-            'targetTable' => $mock,
+            'targetTable' => $table,
             'saveStrategy' => BelongsToMany::SAVE_APPEND,
         ];
 
@@ -1077,7 +1088,7 @@ class BelongsToManyTest extends TestCase
             ],
         ]);
 
-        $mock->expects($this->never())
+        $table->expects($this->never())
             ->method('saveAssociated');
 
         $association = new BelongsToMany('Tags', $config);
@@ -1189,19 +1200,19 @@ class BelongsToManyTest extends TestCase
 
         $jointAssoc = $articles->getAssociation('SpecialTags');
         $this->assertNotEmpty($jointAssoc, 'has many to junction should exist');
-        $this->assertInstanceOf('Cake\ORM\Association\HasMany', $jointAssoc);
+        $this->assertInstanceOf(HasMany::class, $jointAssoc);
         $this->assertEquals('foreign_key', $jointAssoc->getForeignKey());
 
         $articleAssoc = $tags->getAssociation('Articles');
         $this->assertNotEmpty($articleAssoc, 'reverse btm should exist');
-        $this->assertInstanceOf('Cake\ORM\Association\BelongsToMany', $articleAssoc);
+        $this->assertInstanceOf(BelongsToMany::class, $articleAssoc);
         $this->assertEquals($conditions, $articleAssoc->getConditions());
         $this->assertEquals('foreign_key', $articleAssoc->getTargetForeignKey(), 'keys should swap');
         $this->assertEquals('target_foreign_key', $articleAssoc->getForeignKey(), 'keys should swap');
 
         $jointAssoc = $tags->getAssociation('SpecialTags');
         $this->assertNotEmpty($jointAssoc, 'has many to junction should exist');
-        $this->assertInstanceOf('Cake\ORM\Association\HasMany', $jointAssoc);
+        $this->assertInstanceOf(HasMany::class, $jointAssoc);
         $this->assertEquals('target_foreign_key', $jointAssoc->getForeignKey());
     }
 
@@ -1235,7 +1246,7 @@ class BelongsToManyTest extends TestCase
         $table->belongsToMany('Tags');
         $result = $table
             ->find()
-            ->contain(['Tags' => function ($q) {
+            ->contain(['Tags' => function (Query $q) {
                 return $q->select(['id']);
             }])
             ->first();
@@ -1256,7 +1267,7 @@ class BelongsToManyTest extends TestCase
         $table->belongsToMany('Tags');
         $result = $table
             ->find()
-            ->contain(['Tags' => function ($q) {
+            ->contain(['Tags' => function (Query $q) {
                 return $q->select(['two' => $q->newExpr('1 + 1')])->enableAutoFields(true);
             }])
             ->first();
@@ -1323,7 +1334,7 @@ class BelongsToManyTest extends TestCase
             'conditions' => ['SpecialTags.highlighted' => true],
             'through' => 'SpecialTags',
         ]);
-        $query = $table->find()->matching('Tags', function ($q) {
+        $query = $table->find()->matching('Tags', function (Query $q) {
             return $q->where(['Tags.name' => 'tag1']);
         });
         $results = $query->toArray();
@@ -1345,7 +1356,7 @@ class BelongsToManyTest extends TestCase
             'conditions' => [new QueryExpression("name LIKE 'tag%'")],
             'through' => 'SpecialTags',
         ]);
-        $query = $table->find()->matching('Tags', function ($q) {
+        $query = $table->find()->matching('Tags', function (Query $q) {
             return $q->where(['Tags.name' => 'tag1']);
         });
         $results = $query->toArray();
@@ -1367,7 +1378,7 @@ class BelongsToManyTest extends TestCase
             'conditions' => ['SpecialTags.highlighted' => true],
             'through' => 'SpecialTags',
         ]);
-        $query = $table->Tags->find()->matching('Articles', function ($query) {
+        $query = $table->Tags->find()->matching('Articles', function (Query $query) {
             return $query->where(['Articles.id' => 1]);
         });
         // The inner join on special_tags excludes the results.

+ 3 - 11
tests/TestCase/ORM/Behavior/BehaviorRegressionTest.php

@@ -15,17 +15,8 @@ declare(strict_types=1);
  */
 namespace Cake\Test\TestCase\ORM\Behavior;
 
-use Cake\ORM\Behavior\Translate\TranslateTrait;
-use Cake\ORM\Entity;
 use Cake\TestSuite\TestCase;
-
-/**
- * Stub entity class
- */
-class NumberTree extends Entity
-{
-    use TranslateTrait;
-}
+use TestApp\Model\Entity\NumberTree;
 
 /**
  * Behavior regression tests
@@ -54,8 +45,9 @@ class BehaviorRegressionTest extends TestCase
         $table->setPrimaryKey(['id']);
         $table->addBehavior('Tree');
         $table->addBehavior('Translate', ['fields' => ['name']]);
-        $table->setEntityClass(__NAMESPACE__ . '\\NumberTree');
+        $table->setEntityClass(NumberTree::class);
 
+        /** @var \TestApp\Model\Entity\NumberTree[] $all */
         $all = $table->find('threaded')->find('translations');
         $results = [];
         foreach ($all as $node) {

+ 7 - 12
tests/TestCase/ORM/Behavior/CounterCacheBehaviorTest.php

@@ -22,17 +22,7 @@ use Cake\Event\EventInterface;
 use Cake\ORM\Entity;
 use Cake\ORM\Table;
 use Cake\TestSuite\TestCase;
-
-/**
- * Used for testing counter cache with custom finder
- */
-class PostTable extends Table
-{
-    public function findPublished(Query $query, array $options)
-    {
-        return $query->where(['published' => true]);
-    }
-}
+use TestApp\Model\Table\PublishedPostsTable;
 
 /**
  * CounterCacheBehavior test case
@@ -40,6 +30,11 @@ class PostTable extends Table
 class CounterCacheBehaviorTest extends TestCase
 {
     /**
+     * @var \TestApp\Model\Table\PublishedPostsTable
+     */
+    protected $post;
+
+    /**
      * Fixture
      *
      * @var array
@@ -78,7 +73,7 @@ class CounterCacheBehaviorTest extends TestCase
             'connection' => $this->connection,
         ]);
 
-        $this->post = new PostTable([
+        $this->post = new PublishedPostsTable([
             'alias' => 'Post',
             'table' => 'counter_cache_posts',
             'connection' => $this->connection,

+ 9 - 0
tests/test_app/TestApp/Error/TestDebugger.php

@@ -0,0 +1,9 @@
+<?php
+declare(strict_types=1);
+namespace TestApp\Error;
+
+use Cake\Error\Debugger;
+
+class TestDebugger extends Debugger
+{
+}

+ 39 - 0
tests/test_app/TestApp/Error/TestErrorHandler.php

@@ -0,0 +1,39 @@
+<?php
+declare(strict_types=1);
+namespace TestApp\Error;
+
+use Cake\Error\ErrorHandler;
+
+/**
+ * Testing stub.
+ */
+class TestErrorHandler extends ErrorHandler
+{
+    /**
+     * Access the response used.
+     *
+     * @var \Cake\Http\Response
+     */
+    public $response;
+
+    /**
+     * Stub output clearing in tests.
+     *
+     * @return void
+     */
+    protected function _clearOutput(): void
+    {
+        // noop
+    }
+
+    /**
+     * Stub sending responses
+     *
+     * @param \Cake\Http\Response $response
+     * @return void
+     */
+    protected function _sendResponse($response): void
+    {
+        $this->response = $response;
+    }
+}

+ 78 - 0
tests/test_app/TestApp/Http/Client/Adapter/CakeStreamWrapper.php

@@ -0,0 +1,78 @@
+<?php
+declare(strict_types=1);
+namespace TestApp\Http\Client\Adapter;
+
+class CakeStreamWrapper implements \ArrayAccess
+{
+    private $_stream;
+
+    private $_query = [];
+
+    private $_data = [
+        'headers' => [
+            'HTTP/1.1 200 OK',
+        ],
+    ];
+
+    public function stream_open($path, $mode, $options, &$openedPath)
+    {
+        if ($path === 'http://throw_exception/') {
+            throw new \Exception();
+        }
+
+        $query = parse_url($path, PHP_URL_QUERY);
+        if ($query) {
+            parse_str($query, $this->_query);
+        }
+
+        $this->_stream = fopen('php://memory', 'rb+');
+        fwrite($this->_stream, str_repeat('x', 20000));
+        rewind($this->_stream);
+
+        return true;
+    }
+
+    public function stream_close()
+    {
+        return fclose($this->_stream);
+    }
+
+    public function stream_read($count)
+    {
+        if (isset($this->_query['sleep'])) {
+            sleep(1);
+        }
+
+        return fread($this->_stream, $count);
+    }
+
+    public function stream_eof()
+    {
+        return feof($this->_stream);
+    }
+
+    public function stream_set_option($option, $arg1, $arg2)
+    {
+        return false;
+    }
+
+    public function offsetExists($offset)
+    {
+        return isset($this->_data[$offset]);
+    }
+
+    public function offsetGet($offset)
+    {
+        return $this->_data[$offset];
+    }
+
+    public function offsetSet($offset, $value)
+    {
+        $this->_data[$offset] = $value;
+    }
+
+    public function offsetUnset($offset)
+    {
+        unset($this->_data[$offset]);
+    }
+}

+ 14 - 0
tests/test_app/TestApp/Model/Entity/NumberTree.php

@@ -0,0 +1,14 @@
+<?php
+declare(strict_types=1);
+namespace TestApp\Model\Entity;
+
+use Cake\ORM\Behavior\Translate\TranslateTrait;
+use Cake\ORM\Entity;
+
+/**
+ * Stub entity class
+ */
+class NumberTree extends Entity
+{
+    use TranslateTrait;
+}

+ 36 - 0
tests/test_app/TestApp/Model/Table/PublishedPostsTable.php

@@ -0,0 +1,36 @@
+<?php
+declare(strict_types=1);
+/**
+ * Test App Posts Model
+ *
+ * CakePHP : Rapid Development Framework (https://cakephp.org)
+ * Copyright 2005-2012, Cake Software Foundation, Inc.
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc.
+ * @link          https://cakephp.org CakePHP Project
+ * @since         3.0.0
+ * @license       https://opensource.org/licenses/mit-license.php MIT License
+ */
+namespace TestApp\Model\Table;
+
+use Cake\Database\Query;
+use Cake\ORM\Table;
+
+/**
+ * Used for testing counter cache with custom finder
+ */
+class PublishedPostsTable extends Table
+{
+    /**
+     * @param \Cake\Database\Query $query
+     * @param array $options
+     * @return \Cake\Database\Query
+     */
+    public function findPublished(Query $query, array $options)
+    {
+        return $query->where(['published' => true]);
+    }
+}