Skip to content

Commit

Permalink
Migration test are enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafabarmshory committed Jul 7, 2020
1 parent f8c1973 commit ea6c616
Show file tree
Hide file tree
Showing 18 changed files with 433 additions and 510 deletions.
103 changes: 44 additions & 59 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,57 +1,44 @@
<phpunit
bootstrap="./vendor/autoload.php"
stopOnWarning="false"
verbose="false"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
printerClass="Pluf\Test\PlufResultPrinter">
<php>
<var name="DB_DSN" value="sqlite::memory:" />
<var name="DB_USER" value="root" />
<var name="DB_PASSWD" value="" />
<var name="DB_DBNAME" value="pluf_test" />
</php>
<testsuites>
<testsuite name="Core">
<directory>tests/Cache/</directory>
<directory>tests/Logger/</directory>
<file>tests/PlufTest.php</file>
<file>tests/OptionsTest.php</file>
<file>tests/PlufUtilsTest.php</file>
<file>tests/PlufCryptTest.php</file>
</testsuite>
<testsuite name="DB">
<directory>tests/Db/</directory>
</testsuite>
<testsuite name="Data">
<directory>tests/Data/</directory>
<file>tests/ObjectMappertTest.php</file>
</testsuite>
<testsuite name="View">
<directory>tests/Dispatcher/</directory>
<directory>tests/HTTP</directory>
<directory>tests/Middleware/</directory>
<directory>tests/Encoder/</directory>
<directory>tests/Template/</directory>
<directory>tests/Processors/</directory>
</testsuite>
<testsuite name="Utillities">
<directory>tests/Text/</directory>
<directory>tests/Mail/</directory>
</testsuite>
<!-- <testsuite name="Pluf2Suit"> -->
<!-- <directory>tests/Pluf tenant/</directory> -->
<!-- <directory>tests/\Pluf\Migration/</directory> -->
<!-- </testsuite> -->
<!-- <testsuite name="View"> -->
<!-- <directory>tests/Pluf_Paginator/</directory> -->
<!-- </testsuite> -->
<!-- <testsuite name="GraphQl"> -->
<!-- <directory>tests/Pluf_Graphql_Compiler/</directory> -->
<!-- <directory>tests/Pluf_Graphql/</directory> -->
<!-- </testsuite> -->
</testsuites>
<phpunit bootstrap="./vendor/autoload.php" stopOnWarning="false"
verbose="false" backupGlobals="false" backupStaticAttributes="false"
colors="true" printerClass="Pluf\Test\PlufResultPrinter">
<php>
<var name="DB_DSN" value="sqlite::memory:" />
<var name="DB_USER" value="root" />
<var name="DB_PASSWD" value="" />
<var name="DB_DBNAME" value="pluf_test" />
</php>
<testsuites>
<testsuite name="Core">
<directory>tests/Cache/</directory>
<directory>tests/Logger/</directory>
<file>tests/PlufTest.php</file>
<file>tests/OptionsTest.php</file>
<file>tests/PlufUtilsTest.php</file>
<file>tests/PlufCryptTest.php</file>
</testsuite>
<testsuite name="DB">
<directory>tests/Db/</directory>
</testsuite>
<testsuite name="Data">
<directory>tests/Data/</directory>
<!-- <directory>tests/QueryBuilder/</directory> -->
<file>tests/ObjectMappertTest.php</file>
</testsuite>
<testsuite name="View">
<directory>tests/Dispatcher/</directory>
<directory>tests/HTTP</directory>
<directory>tests/Middleware/</directory>
<directory>tests/Encoder/</directory>
<directory>tests/Template/</directory>
<directory>tests/Processors/</directory>
</testsuite>
<testsuite name="Utillities">
<directory>tests/Text/</directory>
<directory>tests/Mail/</directory>
<directory>tests/Migration</directory>
<!-- <directory>tests/Graphql/</directory> -->
</testsuite>
</testsuites>

<!-- Code coverage -->
<filter>
Expand All @@ -60,11 +47,9 @@
<directory suffix=".php">./src6</directory>
</whitelist>
</filter>
<logging>
<log
type="coverage-clover"
target="build/clover.xml"/>
</logging>
<logging>
<log type="coverage-clover" target="build/clover.xml" />
</logging>
</phpunit>


Expand Down
51 changes: 51 additions & 0 deletions src/Data/QueryBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
namespace Pluf\Data;

/**
* Crates a new query
*
* @author maso
*
*/
class QueryBuilder
{

public static function getInstance($config): QueryBuilder
{
if ($config instanceof \Pluf\HTTP\Request) {
return new QueryBuilder\RequestQueryBuilder($config);
}
return new QueryBuilder();
}

public function setView($view): QueryBuilder
{
return $this;
}

public function setStart($start): QueryBuilder
{
return $this;
}

public function setLimit($limit): QueryBuilder
{
return $this;
}

public function setOrder($key, $order): QueryBuilder
{
return $this;
}

public function addFilter($key, $value): QueryBuilder
{
return $this;
}

public function build(): Query
{
return null;
}
}

163 changes: 163 additions & 0 deletions src/Data/QueryBuilder/RequestQueryBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?php
namespace Pluf\Data\QueryBuilder;

use Pluf\HTTP\Request;

class RequestQueryBuilder extends \Pluf\Data\QueryBuilder
{

const SEARCH_QUERY_KEY = '_px_q';

const CURRENT_PAGE_KEY = '_px_p';

const PAGE_SIZE_KEY = '_px_ps';

const SORT_KEY_KEY = '_px_sk';

const SORT_ORDER_KEY = '_px_so';

const FILTER_KEY_KEY = '_px_fk';

const FILTER_VALUE_KEY = '_px_fv';

/**
* Load options from user request
*
* Here is list of all possible values
*
* <ul>
* <li>_px_q : Query string to search.</li>
* <li>_px_p : Current page.</li>
* <li>_px_sk : Sort key.</li>
* <li>_px_so : Sort order.</li>
* <li>_px_fk : Filter key.</li>
* <li>_px_fv : Filter value.</li>
* <ul>
*
* @param
* \Pluf\HTTP\Request The request
*/
function __construct(Request $request)
{
// load query
if (isset($request->REQUEST[self::SEARCH_QUERY_KEY])) {
$this->setQueryString($request->REQUEST[self::SEARCH_QUERY_KEY]);
}

$this->loadPage($request)
->loadSorts($request)
->loadFilters($request)
->loadQuery($request);

// Load options
$this->loadSortOptions($request);
$this->loadFilterOptions($request);
}

/*
* load current page
*/
private function loadPage(Request $request): RequestQueryBuilder
{
$page = 0;
$pageSize = 30;
if (isset($request->REQUEST[self::CURRENT_PAGE_KEY])) {
// >> Page number
$page = $request->REQUEST[self::CURRENT_PAGE_KEY];
if (! isset($page)) {
$page = 0;
}
$page = (int) $page;
}
if (isset($request->REQUEST[self::PAGE_SIZE_KEY])) {
// Page size
$pageSize = $request->REQUEST[self::PAGE_SIZE_KEY];
if (! isset($pageSize)) {
$pageSize = 30;
}
$pageSize = (int) $pageSize;
}
// >> set query
$this->setStart($page * $pageSize)->setLimit($pageSize);
return $this;
}

/*
* load current page
*/
private function loadSorts(Request $request): RequestQueryBuilder
{
if (! isset($request->REQUEST[self::SORT_KEY_KEY])) {
$this->sort_order = [];
return;
}
// Sort orders
$keys = $request->REQUEST[self::SORT_KEY_KEY];
$vals = $request->REQUEST[self::SORT_ORDER_KEY];

if (! is_array($keys)) {
$keys = [
$keys
];
}
if (! is_array($vals)) {
$vals = [
$vals
];
}

for ($i = 0; $i < sizeof($keys); $i ++) {
$key = $keys[$i];
$order = 'ASC';
if ($vals[$i] === 'd') {
$order = 'DESC';
}
$this->setOrder($key, $order);
}

return $this;
}

/*
* load current page
*/
private function loadFilters(Request $request): RequestQueryBuilder
{

// check filter option
if (! array_key_exists(self::FILTER_KEY_KEY, $request->REQUEST)) {
return;
}

$keys = $request->REQUEST[self::FILTER_KEY_KEY];
$vals = $request->REQUEST[self::FILTER_VALUE_KEY];
if (! is_array($keys)) {
$keys = [
$keys
];
}
if (! is_array($vals)) {
$vals = [
$vals
];
}

// categorize filters
for ($i = 0; $i < sizeof($keys); $i ++) {
$key = $keys[$i];
$value = $vals[$i];
$this->addFilter($key, $value);
}

return $this;
}

/*
* load current page
*/
private function loadQuery(Request $request): RequestQueryBuilder
{
return $this;
}
}

5 changes: 3 additions & 2 deletions src/Pluf/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
namespace Pluf\Pluf;

use Pluf\SQL;
use Pluf\Text;
use Pluf\Pluf\Search\Occ;
use Pluf\Pluf\Search\Stats;
Expand Down Expand Up @@ -184,7 +185,7 @@ public static function index($doc, $stemmer = 'Pluf_Text_Stemmer_Porter')
}
// Drop the last indexation.
$gocc = new Occ();
$sql = new Pluf_SQL('DELETE FROM ' . $gocc->getSqlTable() . ' WHERE model_class=%s AND model_id=%s', array(
$sql = new SQL('DELETE FROM ' . $gocc->getSqlTable() . ' WHERE model_class=%s AND model_id=%s', array(
$doc->_model,
$doc->id
));
Expand Down Expand Up @@ -229,7 +230,7 @@ public static function index($doc, $stemmer = 'Pluf_Text_Stemmer_Porter')
$occ->create();
}
// update the stats
$sql = new Pluf_SQL('model_class=%s AND model_id=%s', array(
$sql = new SQL('model_class=%s AND model_id=%s', array(
$doc->_model,
$doc->id
));
Expand Down
Loading

0 comments on commit ea6c616

Please sign in to comment.