compatibility with ext-pq/master
authorMichael Wallner <mike@php.net>
Mon, 6 Oct 2014 10:11:27 +0000 (12:11 +0200)
committerMichael Wallner <mike@php.net>
Mon, 6 Oct 2014 10:11:27 +0000 (12:11 +0200)
lib/pq/Gateway/Table/CacheInterface.php
lib/pq/Gateway/Table/StaticCache.php
tests/lib/pq/Gateway/CellTest.php
tests/lib/pq/Gateway/RowsetTest.php
tests/setup.inc

index 5e30fac7f84c7a6987f8bf43e460ee05643d6956..f36663f78b9976712ee14c9953441c6121b27a09 100644 (file)
@@ -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);
 }
index 7f313464ec745aedf134bbfaac4842e444532275..34dae3fd7ee37d192827bc4425471555d5d0e9be 100644 (file)
@@ -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;
+       }
 }
index de57a4fbcc7f25e91eaa6628382a88d3599c5adf..8ec28598ad220ff489ca8e3d1bf7c955125f9ea1 100644 (file)
@@ -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)."\"=>";
index 49e1853b35088968b3e2cc4c853c38f34c223b4d..61f6b11af4668fa1b30c8e8566b47eba8de6cfa9 100644 (file)
@@ -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()));
        }
index 6f1b70501be8c91f2ba96a9fb5a88ea41338723d..fa7af13428ec71522b02d220dd6d81eb3ff0eb8e 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 
+ini_set("date.timezone", "UTC");
+ini_set("error_reporting", E_ALL);
+
 const PQ_TEST_DSN = "";
 
 const PQ_TEST_SETUP_SQL = <<<SQL