mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-05-15 19:10:45 +02:00
PSR-0 for namespace and filename + tests
This commit is contained in:
parent
953fde0c4f
commit
f040f8043d
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns;
|
namespace DesignPatterns\FluentInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fluent interface pattern
|
* fluent interface pattern
|
||||||
@ -52,9 +52,15 @@ class SQL
|
|||||||
$this->_where[] = $condition;
|
$this->_where[] = $condition;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$instance = new SQL();
|
/**
|
||||||
$instance->select(array('foo', 'bar'))
|
* Gets the query, just an example of building a query,
|
||||||
->from('foobar', 'f')
|
* no check on consistency
|
||||||
->where('f.bar = ?');
|
*/
|
||||||
|
public function getQuery()
|
||||||
|
{
|
||||||
|
return 'SELECT ' . implode(',', $this->_fields)
|
||||||
|
. ' FROM ' . implode(',', $this->_from)
|
||||||
|
. ' WHERE ' . implode(' AND ', $this->_where);
|
||||||
|
}
|
||||||
|
}
|
28
Tests/FluentInterface/FluentInterfaceTest.php
Normal file
28
Tests/FluentInterface/FluentInterfaceTest.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DesignPatternPHP
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace DesignPatterns\Tests\FluentInterface;
|
||||||
|
|
||||||
|
use DesignPatterns\FluentInterface\SQL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FluentInterfaceTest tests the fluent interface SQL
|
||||||
|
*/
|
||||||
|
class FluentInterfaceTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testBuildSQL()
|
||||||
|
{
|
||||||
|
$instance = new SQL();
|
||||||
|
$query = $instance->select(array('foo', 'bar'))
|
||||||
|
->from('foobar', 'f')
|
||||||
|
->where('f.bar = ?')
|
||||||
|
->getQuery();
|
||||||
|
|
||||||
|
$this->assertEquals('SELECT foo,bar FROM foobar AS f WHERE f.bar = ?', $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user