diff --git a/README.md b/README.md
index 1f642b8..a00a55c 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,16 @@ require_once(Netflex\SDK::bootstrap);
composer run-script tests
```
+## Updating snapshots
+
+When an existing snapshot test has been updated, or its behaviour has been modified, the snapshot will have to be updated to prevent the tests from failing.
+
+To update the snapshots, run the following command.
+
+```bash
+composer run-script tests:update-snapshots
+```
+
Copyright © 2019 **[Apility AS](https://apility.no)**
diff --git a/composer.json b/composer.json
index 662ab59..1dd78fe 100644
--- a/composer.json
+++ b/composer.json
@@ -67,6 +67,7 @@
"spatie/phpunit-snapshot-assertions": "^2.1"
},
"scripts": {
- "tests": "vendor/bin/phpunit --testdox --colors=always"
+ "tests": "vendor/bin/phpunit --testdox --colors=always",
+ "tests:update-snapshots": "vendor/bin/phpunit --colors=always -d --update-snapshots"
}
}
diff --git a/src/cli.php b/src/cli.php
index ea901e9..00ca95e 100644
--- a/src/cli.php
+++ b/src/cli.php
@@ -1,6 +1,9 @@
use_time) {
+ $start = null;
+
+ try {
+ $start = Carbon::parse($this->start);
+ } catch (Exception $ex) {
+ $start = Carbon::parse(0);
+ }
+
+ try {
+ $stop = $this->stop ? $this->stop : PHP_INT_MAX;
+ $stop = Carbon::parse($stop);
+ } catch (Exception $ex) {
+ $stop = Carbon::parse(PHP_INT_MAX);
+ }
+
+ $now = Carbon::now();
+
+ return $now->gte($start) && $now->lte($stop);
+ }
+
+ return (bool) $published;
+ }
+
public function save()
{
static::performHookOn($this, 'saving');
@@ -273,7 +307,7 @@ public static function all()
$cacheKey = 'entry/' . $entry['id'];
NF::$cache->save($cacheKey, $entry);
return static::generateObject($entry);
- }, $response))->values();
+ }, $response))->filter()->values();
}
public static function find($id)
@@ -386,7 +420,7 @@ public static function resolveOrFail($slug)
public static function query(...$args)
{
$structureId = (new static)->directory;
- $query = new StructureQuery($structureId, new static);
+ $query = new StructureQuery($structureId, new static, static::$_fetch_unpublished);
return call_user_func_array([$query, 'query'], $args);
}
@@ -394,7 +428,7 @@ public static function query(...$args)
public static function count()
{
$structureId = (new static)->directory;
- $query = new StructureQuery($structureId, new static);
+ $query = new StructureQuery($structureId, new static, static::$_fetch_unpublished);
return call_user_func_array([$query, 'count'], []);
}
@@ -402,7 +436,7 @@ public static function count()
public static function where(...$args)
{
$structureId = (new static)->directory;
- $query = new StructureQuery($structureId, new static);
+ $query = new StructureQuery($structureId, new static, static::$_fetch_unpublished);
return call_user_func_array([$query, 'where'], $args);
}
@@ -410,7 +444,7 @@ public static function where(...$args)
public static function pluck(...$args)
{
$structureId = (new static)->directory;
- $query = new StructureQuery($structureId, new static);
+ $query = new StructureQuery($structureId, new static, static::$_fetch_unpublished);
return call_user_func_array([$query, 'pluck'], $args);
}
@@ -418,7 +452,7 @@ public static function pluck(...$args)
public static function whereBetween(...$args)
{
$structureId = (new static)->directory;
- $query = new StructureQuery($structureId, new static);
+ $query = new StructureQuery($structureId, new static, static::$_fetch_unpublished);
return call_user_func_array([$query, 'whereBetween'], $args);
}
@@ -426,7 +460,7 @@ public static function whereBetween(...$args)
public static function orderBy(...$args)
{
$structureId = (new static)->directory;
- $query = new StructureQuery($structureId, new static);
+ $query = new StructureQuery($structureId, new static, static::$_fetch_unpublished);
return call_user_func_array([$query, 'orderBy'], $args);
}
@@ -434,7 +468,7 @@ public static function orderBy(...$args)
public static function first()
{
$structureId = (new static)->directory;
- $query = new StructureQuery($structureId, new static);
+ $query = new StructureQuery($structureId, new static, static::$_fetch_unpublished);
return call_user_func_array([$query, 'firstOrFail'], []);
}
@@ -442,7 +476,7 @@ public static function first()
public static function paginate(...$args)
{
$structureId = (new static)->directory;
- $query = new StructureQuery($structureId, new static);
+ $query = new StructureQuery($structureId, new static, static::$_fetch_unpublished);
return call_user_func_array([$query, 'paginate'], $args);
}
@@ -462,7 +496,15 @@ public static function generateObject($data)
return $revision;
}
- return new static($data);
+ $entry = new static($data);
+
+ if ($entry) {
+ if (!$_mode && static::$_fetch_unpublished === false || static::$_fetch_unpublished === false && $_mode === 'cli') {
+ return $entry->published ? $entry : null;
+ }
+
+ return $entry;
+ }
}
private static function bootUnlessBooted()
diff --git a/src/model/StructureQuery.php b/src/model/StructureQuery.php
index f65086c..0564346 100644
--- a/src/model/StructureQuery.php
+++ b/src/model/StructureQuery.php
@@ -26,13 +26,17 @@ class StructureQuery
private $_firstPageSize = null;
private $_fieldsModified = false;
- public function __construct($directory, $class)
+ public function __construct($directory, $class, $fetchUnpublished = true)
{
$this->_class = $class;
$this->_directory = $directory;
$this->_search = new ElasticSearch();
$this->_search->directory($this->_directory);
$this->_search->limit(10000);
+
+ if (!$fetchUnpublished) {
+ $this->_search->where('published', true);
+ }
}
private function isArgsArray($args)