From f040f8043d28d97d841b5ad0f11b47c617e88227 Mon Sep 17 00:00:00 2001 From: Trismegiste Date: Mon, 13 May 2013 20:13:19 +0200 Subject: [PATCH] PSR-0 for namespace and filename + tests --- .../{FluentInterface.php => SQL.php} | 18 ++++++++---- Tests/FluentInterface/FluentInterfaceTest.php | 28 +++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) rename FluentInterface/{FluentInterface.php => SQL.php} (73%) create mode 100644 Tests/FluentInterface/FluentInterfaceTest.php diff --git a/FluentInterface/FluentInterface.php b/FluentInterface/SQL.php similarity index 73% rename from FluentInterface/FluentInterface.php rename to FluentInterface/SQL.php index c7a7e7a..84034da 100644 --- a/FluentInterface/FluentInterface.php +++ b/FluentInterface/SQL.php @@ -1,6 +1,6 @@ _where[] = $condition; return $this; } + + /** + * Gets the query, just an example of building a query, + * no check on consistency + */ + public function getQuery() + { + return 'SELECT ' . implode(',', $this->_fields) + . ' FROM ' . implode(',', $this->_from) + . ' WHERE ' . implode(' AND ', $this->_where); + } } - -$instance = new SQL(); -$instance->select(array('foo', 'bar')) - ->from('foobar', 'f') - ->where('f.bar = ?'); \ No newline at end of file diff --git a/Tests/FluentInterface/FluentInterfaceTest.php b/Tests/FluentInterface/FluentInterfaceTest.php new file mode 100644 index 0000000..7dec8d8 --- /dev/null +++ b/Tests/FluentInterface/FluentInterfaceTest.php @@ -0,0 +1,28 @@ +select(array('foo', 'bar')) + ->from('foobar', 'f') + ->where('f.bar = ?') + ->getQuery(); + + $this->assertEquals('SELECT foo,bar FROM foobar AS f WHERE f.bar = ?', $query); + } + +} \ No newline at end of file