Page MenuHomePhabricator

No OneTemporary

diff --git a/db/drivers/mysqlPDORes.php b/db/drivers/mysqlPDORes.php
index 4ed45c5..60286ee 100644
--- a/db/drivers/mysqlPDORes.php
+++ b/db/drivers/mysqlPDORes.php
@@ -1,67 +1,67 @@
<?php namespace spitfire\storage\database\drivers;
use PDO;
/**
* This class works as a traditional resultset. It acts as an adapter between the
* driver's raw data retrieving and the logical record classes.
*
* @author César de la Cal <cesar@magic3w.com>
*/
class mysqlPDOResultSet implements \spitfire\storage\database\ResultSetInterface
{
/**
* Contains the raw pointer that PDO has created when executing the query.
* This allows spitfire to retrieve all the data needed to create a complete
* database record.
*
* @var PDOStatement
*/
private $result;
/**
* This is a reference to the table this resultset belongs to. This allows
* Spitfire to retrieve data about the model and the fields the datatype has.
*
* @var \spitfire\storage\database\Table
*/
private $table;
public function __construct(\spitfire\storage\database\Table$table, $stt) {
$this->result = $stt;
$this->table = $table;
}
public function fetch() {
$data = $this->result->fetch(PDO::FETCH_ASSOC);
#If the data does not contain anything we return a null object
if (!$data) { return null; }
$_record = array_map( Array($this->table->getDB()->getEncoder(), 'decode'), $data);
$record = $this->table->newRecord($_record);
return $record;
}
public function fetchAll() {
$data = $this->result->fetchAll(PDO::FETCH_ASSOC);
foreach ($data as &$record) {
- $record = $this->table->getDb()->table($this->table->getModel()->getName())->newRecord(
+ $record = $this->table->newRecord(
array_map( Array($this->table->getDB()->getEncoder(), 'decode'), $record)
);
}
- return $data;
+ return new \spitfire\core\Collection($data);
}
/**
* Returns the data the way any associative adapter would return it. This allows
* your app to withdraw raw data without it being treated by the framework.
*
* @return mixed
*/
public function fetchArray() {
return $this->result->fetch(PDO::FETCH_ASSOC);
}
}
diff --git a/storage/database/pagination/MockPaginator.php b/storage/database/pagination/MockPaginator.php
new file mode 100644
index 0000000..386cc9e
--- /dev/null
+++ b/storage/database/pagination/MockPaginator.php
@@ -0,0 +1,84 @@
+<?php namespace spitfire\storage\database\pagination;
+
+/*
+ * The MIT License
+ *
+ * Copyright 2018 César de la Cal Bretschneider <cesar@magic3w.com>.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+class MockPaginator implements PaginationInterface
+{
+
+ private $current;
+
+ public function __construct($current = 1) {
+ $this->current = $current;
+ }
+
+ public function after() {
+ return '::after' . PHP_EOL;
+ }
+
+ public function before() {
+ return '::before' . PHP_EOL;
+ }
+
+ public function current() {
+ return $this->current;
+ }
+
+ public function emptyResultMessage() {
+ return '::empty' . PHP_EOL;
+ }
+
+ public function first() {
+ return '::first' . PHP_EOL;
+ }
+
+ public function last($number) {
+ return '::last' . PHP_EOL;
+ }
+
+ public function next() {
+ return '::next' . PHP_EOL;
+ }
+
+ public function page($number) {
+ return '::page #' . $number . PHP_EOL;
+ }
+
+ public function previous() {
+ return '::previous' . PHP_EOL;
+ }
+
+ public function gap() {
+ return '::gap' . PHP_EOL;
+ }
+
+ public function jumpTo($total) {
+ return '::jumpTo ' . $total . PHP_EOL;
+ }
+
+ public function pageOf($total) {
+ return '::pageOf ' . $total . PHP_EOL;
+ }
+
+}
diff --git a/tests/storage/database/pagination/PaginatorTest.php b/tests/storage/database/pagination/PaginatorTest.php
index afb9af9..aa6d695 100644
--- a/tests/storage/database/pagination/PaginatorTest.php
+++ b/tests/storage/database/pagination/PaginatorTest.php
@@ -1,65 +1,67 @@
<?php namespace tests\spitfire\storage\database\pagination;
use IntegerField;
use PHPUnit\Framework\TestCase;
use spitfire\exceptions\PrivateException;
use spitfire\storage\database\drivers\mysqlpdo\Driver;
+use spitfire\storage\database\pagination\MockPaginator;
+use spitfire\storage\database\pagination\Paginator;
use spitfire\storage\database\Schema;
use spitfire\storage\database\Settings;
use spitfire\storage\database\Table;
use StringField;
class PaginatorTest extends TestCase
{
private $db;
/**
* The table we're testing.
*
* @var Table
*/
private $table;
private $schema;
public function setUp() {
//Just in case Mr. Bergmann decides to add code to the setUp
parent::setUp();
try {
$this->db = new Driver(Settings::fromArray([]));
$this->db->create();
$this->schema = new Schema('test');
$this->schema->field1 = new IntegerField(true);
$this->schema->field2 = new StringField(255);
$this->table = new Table($this->db, $this->schema);
$this->table->getLayout()->create();
}
catch (PrivateException$e) {
$this->markTestSkipped('MySQL PDO driver is not available.');
}
}
public function tearDown() {
$this->db->destroy();
}
public function testPagination() {
for ($i = 0; $i < 100; $i++) {
$record = $this->table->newRecord();
$record->field1 = $i;
$record->field2 = 'Test';
$record->store();
}
$query = $this->table->getAll();
- $paginator = new PaginatorTest($query);
+ $paginator = new Paginator($query, new MockPaginator(1));
$this->assertEquals(20, $paginator->records()->count());
}
}

File Metadata

Mime Type
text/x-diff
Expires
Apr 12 2021, 3:56 AM (9 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1925
Default Alt Text
(6 KB)

Event Timeline