From: Michael Wallner Date: Mon, 6 Oct 2014 10:11:27 +0000 (+0200) Subject: compatibility with ext-pq/master X-Git-Tag: v2.0.0~8 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=commitdiff_plain;h=80c4d645e1650304b1dbcae85dbf17a6593896e4 compatibility with ext-pq/master --- diff --git a/lib/pq/Gateway/Table/CacheInterface.php b/lib/pq/Gateway/Table/CacheInterface.php index 5e30fac..f36663f 100644 --- a/lib/pq/Gateway/Table/CacheInterface.php +++ b/lib/pq/Gateway/Table/CacheInterface.php @@ -30,4 +30,18 @@ interface CacheInterface * @return \pq\Gateway\Table\CacheInterface */ function del($key); + + /** + * Lock an item + * @param string $key + * @return \pq\Gateway\Table\CacheInterface + */ + function lock($key); + + /** + * Unlock an item + * @param string $key + * @return \pq\Gateway\Table\CacheInterface + */ + function unlock($key); } diff --git a/lib/pq/Gateway/Table/StaticCache.php b/lib/pq/Gateway/Table/StaticCache.php index 7f31346..34dae3f 100644 --- a/lib/pq/Gateway/Table/StaticCache.php +++ b/lib/pq/Gateway/Table/StaticCache.php @@ -48,4 +48,24 @@ class StaticCache implements CacheInterface unset(static::$cache[$key]); return $this; } + + /** + * @inheritdoc + * @param string $key + * @return \pq\Gateway\Table\StaticCache + */ + function lock($key) { + /* no possible concurrency */ + return $this; + } + + /** + * @inheritdoc + * @param string $key + * @return \pq\Gateway\Table\StaticCache + */ + function unlock($key) { + /* no possible concurrency */ + return $this; + } } diff --git a/tests/lib/pq/Gateway/CellTest.php b/tests/lib/pq/Gateway/CellTest.php index de57a4f..8ec2859 100644 --- a/tests/lib/pq/Gateway/CellTest.php +++ b/tests/lib/pq/Gateway/CellTest.php @@ -77,7 +77,8 @@ class CellTest extends \PHPUnit_Framework_TestCase { $row->list = [$row->list->get()]; $row->update(); $this->assertEquals([[0,1,2]], $row->list->get()); - $this->setExpectedException("PHPUnit_Framework_Error_Notice", "Indirect modification of overloaded element of pq\Gateway\Cell has no effect"); + $this->setExpectedException("PHPUnit_Framework_Error_Notice", + "Indirect modification of overloaded element of pq\Gateway\Cell has no effect"); $row->list[0][0] = -1; } @@ -99,19 +100,19 @@ class CellTest extends \PHPUnit_Framework_TestCase { } } -class Hstore implements \pq\ConverterInterface +class Hstore implements \pq\Converter { protected $types; function __construct(\pq\Types $types) { - $this->types = $types; + $this->types = $types["hstore"]->oid; } function convertTypes() { - return [$this->types["hstore"]->oid]; + return [$this->types]; } - function convertFromString($string) { + function convertFromString($string, $type) { return eval("return [$string];"); } - function convertToString($data) { + function convertToString($data, $type) { $string = ""; foreach ($data as $k => $v) { $string .= "\"".addslashes($k)."\"=>"; diff --git a/tests/lib/pq/Gateway/RowsetTest.php b/tests/lib/pq/Gateway/RowsetTest.php index 49e1853..61f6b11 100644 --- a/tests/lib/pq/Gateway/RowsetTest.php +++ b/tests/lib/pq/Gateway/RowsetTest.php @@ -111,12 +111,16 @@ class RowsetTest extends \PHPUnit_Framework_TestCase { } public function testJsonSerialize() { - $json = sprintf('[{"id":"1","created":"%s","counter":"-1","number":"-1.1","data":"yesterday","list":[-1,0,1],"prop":null}' - .',{"id":"2","created":"%s","counter":"0","number":"0","data":"today","list":[0,1,2],"prop":null}' - .',{"id":"3","created":"%s","counter":"1","number":"1.1","data":"tomorrow","list":[1,2,3],"prop":null}]', - new \pq\DateTime("yesterday"), - new \pq\DateTime("today"), - new \pq\DateTime("tomorrow") + $yday = new \pq\DateTime("yesterday"); + $tday = new \pq\DateTime("today"); + $tmrw = new \pq\DateTime("tomorrow"); + + $yday->format = $tday->format = $tmrw->format = "Y-m-d H:i:s.u"; + + $json = sprintf('[{"id":1,"created":"%s","counter":-1,"number":-1.1,"data":"yesterday","list":[-1,0,1],"prop":null}' + .',{"id":2,"created":"%s","counter":0,"number":0,"data":"today","list":[0,1,2],"prop":null}' + .',{"id":3,"created":"%s","counter":1,"number":1.1,"data":"tomorrow","list":[1,2,3],"prop":null}]', + $yday, $tday, $tmrw ); $this->assertJsonStringEqualsJsonString($json, json_encode($this->table->find())); } diff --git a/tests/setup.inc b/tests/setup.inc index 6f1b705..fa7af13 100644 --- a/tests/setup.inc +++ b/tests/setup.inc @@ -1,5 +1,8 @@