diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..b735373 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,35 @@ +--- +name: Bug report +about: Create a report to help us improve + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..066b2d9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,17 @@ +--- +name: Feature request +about: Suggest an idea for this project + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..322b7d0 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1 @@ +Contributing is pretty easy. This is a pre-release library and this is my first github open source project, so I am very open to input of any kind. diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..53f8ef5 --- /dev/null +++ b/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,9 @@ +**what Issue is this pull request refering to** +Please link the issue using the #number reference + +**Have The Tests Been Updated in any way?:** yes/no + +**Are all tests passing on your local dev branch?:** yes/no + +**If all tests are not passing** +Please explain why, with the tests not passing you feel this pull request should be merged diff --git a/README.md b/README.md index 372edce..be1f2c3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# php-keyvaluestore [![Travis (.com) branch](https://img.shields.io/travis/com/ryanwhowe/php-keyvaluestore/1.0.svg)](https://github.com/ryanwhowe/php-keyvaluestore) [![GitHub (pre-)release](https://img.shields.io/github/release/ryanwhowe/php-keyvaluestore/all.svg)](https://github.com/ryanwhowe/php-keyvaluestore) [![GitHub issues](https://img.shields.io/github/issues-raw/ryanwhowe/php-keyvaluestore.svg)](https://github.com/ryanwhowe/php-keyvaluestore) [![Test Coverage](https://img.shields.io/badge/Test%20Coverage-100%25-brightgreen.svg)](https://github.com/ryanwhowe/php-keyvaluestore) +# php-keyvaluestore [![Travis (.com)](https://img.shields.io/travis/com/ryanwhowe/php-keyvaluestore.svg)](https://github.com/ryanwhowe/php-keyvaluestore) [![GitHub (pre-)release](https://img.shields.io/github/release/ryanwhowe/php-keyvaluestore/all.svg)](https://github.com/ryanwhowe/php-keyvaluestore) [![GitHub issues](https://img.shields.io/github/issues-raw/ryanwhowe/php-keyvaluestore.svg)](https://github.com/ryanwhowe/php-keyvaluestore) [![Codecov branch](https://img.shields.io/codecov/c/ryanwhowe/php-keyvaluestore/master.svg)](https://github.com/ryanwhowe/php-keyvaluestore) This is a database backed key/value store setter and getter library with additional functionality This extends the key/value store in several ways diff --git a/phpunit.xml b/phpunit.xml index 03720ec..ceee341 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,4 +18,7 @@ src + + + diff --git a/src/KeyValue.php b/src/KeyValue.php index 71045f9..720460e 100644 --- a/src/KeyValue.php +++ b/src/KeyValue.php @@ -99,7 +99,6 @@ public function getGroupingSet() { $sql = " SELECT - :grouping as `grouping`, keyset.`key`, (SELECT `value` FROM `ValueStore` WHERE grouping = :grouping and `key` = keyset.`key` ORDER BY last_update DESC, id DESC LIMIT 1) as `value`, (SELECT `last_update` FROM `ValueStore` WHERE grouping = :grouping and `key` = keyset.`key` ORDER BY last_update DESC, id DESC LIMIT 1) as `last_update` diff --git a/src/KeyValue/Multi.php b/src/KeyValue/Multi.php index bf158df..39e79ea 100644 --- a/src/KeyValue/Multi.php +++ b/src/KeyValue/Multi.php @@ -54,7 +54,6 @@ public function get($key) { $sql = " SELECT - `key`, `value`, `last_update` FROM @@ -87,7 +86,6 @@ public function getSet($key) { $sql = " SELECT - `key`, `value`, `last_update`, `value_created` @@ -97,7 +95,7 @@ public function getSet($key) `grouping` = :grouping AND `key` = :key ORDER BY - value_created DESC + id ASC ;"; $stmt = $this->connection->prepare($sql); $stmt->bindValue(':grouping', $this->getGrouping(), \PDO::PARAM_STR); diff --git a/tests/KeyValue/DistinctSeriesTest.php b/tests/KeyValue/DistinctSeriesTest.php index d7c6c37..43b0878 100644 --- a/tests/KeyValue/DistinctSeriesTest.php +++ b/tests/KeyValue/DistinctSeriesTest.php @@ -106,8 +106,7 @@ public function getGroupingSet($testSet) } $expected_values = \array_keys($expected_values); $expected_value = end($expected_values); - $expected[] = array('grouping' => $testGroup, 'key' => \strtolower($key), 'value' => $expected_value); - + $expected[] = array('key' => \strtolower($key), 'value' => $expected_value); } $result = $seriesValue->getGroupingSet(); @@ -162,7 +161,7 @@ public function get($key, $values) $expected_value = $set_value; } - $this->assertEquals(array('key' => \strtolower($key), 'value' => $expected_value), $result); + $this->assertEquals(array('value' => $expected_value), $result); } /** @@ -202,7 +201,7 @@ public function getSet($testSet) } } foreach ($expected_values as $values => $item) { - $expected[] = array('key' => \strtolower($key), 'value' => $values); + $expected[] = array('value' => $values); } $result = $distinctSeries->getSet($key); // unset the timestamps, which will vary with time @@ -295,7 +294,7 @@ public function set($key, $values) $expected_value = $set_value; } - $this->assertEquals(array('key' => \strtolower($key), 'value' => $expected_value), $result); + $this->assertEquals(array('value' => $expected_value), $result); } /** @@ -318,4 +317,39 @@ public function create() $this->assertEquals($testGroupName, $resultGroupName); $this->assertInstanceOf('RyanWHowe\KeyValueStore\KeyValue\DistinctSeries', $seriesValue); } + + /** + * @test + * @covers \RyanWHowe\KeyValueStore\Manager::__construct + * @covers \RyanWHowe\KeyValueStore\Manager::create + * @covers \RyanWHowe\KeyValueStore\Manager::createTable + * @covers \RyanWHowe\KeyValueStore\Manager::dropTable + * @covers \RyanWHowe\KeyValueStore\KeyValue::__construct + * @covers \RyanWHowe\KeyValueStore\KeyValue::create + * @covers \RyanWHowe\KeyValueStore\KeyValue::formatGrouping + * @covers \RyanWHowe\KeyValueStore\KeyValue::getAllKeys + * @covers \RyanWHowe\KeyValueStore\KeyValue::getGrouping + * @covers \RyanWHowe\KeyValueStore\KeyValue::getId + * @covers \RyanWHowe\KeyValueStore\KeyValue::insert + * @covers \RyanWHowe\KeyValueStore\KeyValue\DistinctSeries::set + * @covers \RyanWHowe\KeyValueStore\KeyValue\DistinctSeries::update + * @dataProvider nonUniqueKeyDataProvider + * @throws \Exception + */ + public function uniqueKeysCheck($testSet) + { + $testGroup = 'DistinctSeriesUniqueKeys'; + $distinctSeries = DistinctSeries::create($testGroup, self::$connection); + $expected = array(); + foreach ($testSet as $test) { + $key = $test['key']; + foreach ($test['values'] as $value) { + $distinctSeries->set($key, $value); + } + $expected[\strtolower($key)] = true; + $result = $distinctSeries->getAllKeys(); + $this->assertEquals(array_keys($expected), $result); + } + + } } diff --git a/tests/KeyValue/SeriesTest.php b/tests/KeyValue/SeriesTest.php index d50ee0e..bb2e420 100644 --- a/tests/KeyValue/SeriesTest.php +++ b/tests/KeyValue/SeriesTest.php @@ -43,7 +43,7 @@ public function set($key, $values) $result = $seriesValue->get($key); unset($result['last_update']); unset($result['value_created']); - $this->assertEquals(array('key' => \strtolower($key), 'value' => $value), $result); + $this->assertEquals(array('value' => $value), $result); } /** @@ -74,7 +74,7 @@ public function getSet($testSet) $key = $item['key']; foreach ($item['values'] as $value) { $seriesValue->set($key, $value); - $expected[] = array('key' => \strtolower($key), 'value' => $value); + $expected[] = array('value' => $value); } $result = $seriesValue->getSet($key); @@ -172,7 +172,7 @@ public function getGroupingSet($testSet) $singleValue->set($key, $value); $expected_value = $value; // we expect the last value set } - $expected[] = array('grouping' => $testGroup, 'key' => \strtolower($key), 'value' => $expected_value); + $expected[] = array('key' => \strtolower($key), 'value' => $expected_value); } $result = $singleValue->getGroupingSet(); @@ -217,7 +217,7 @@ public function get($key, $values) $result = $seriesValue->get($key); unset($result['last_update']); unset($result['value_created']); - $this->assertEquals(array('key' => \strtolower($key), 'value' => $value), $result); + $this->assertEquals(array('value' => $value), $result); } /** @@ -274,4 +274,39 @@ public function delete() $result = $seriesValue->get($key); $this->assertFalse($result); } + + /** + * @test + * @covers \RyanWHowe\KeyValueStore\Manager::__construct + * @covers \RyanWHowe\KeyValueStore\Manager::create + * @covers \RyanWHowe\KeyValueStore\Manager::createTable + * @covers \RyanWHowe\KeyValueStore\Manager::dropTable + * @covers \RyanWHowe\KeyValueStore\KeyValue::__construct + * @covers \RyanWHowe\KeyValueStore\KeyValue::create + * @covers \RyanWHowe\KeyValueStore\KeyValue::formatGrouping + * @covers \RyanWHowe\KeyValueStore\KeyValue::getAllKeys + * @covers \RyanWHowe\KeyValueStore\KeyValue::getGrouping + * @covers \RyanWHowe\KeyValueStore\KeyValue::getId + * @covers \RyanWHowe\KeyValueStore\KeyValue::insert + * @covers \RyanWHowe\KeyValueStore\KeyValue\Series::set + * @covers \RyanWHowe\KeyValueStore\KeyValue\Series::update + * @dataProvider nonUniqueKeyDataProvider + * @throws \Exception + */ + public function uniqueKeysCheck($testSet) + { + $testGroup = 'SingleUniqueKeys'; + $series = Series::create($testGroup, self::$connection); + $expected = array(); + foreach ($testSet as $test) { + $key = $test['key']; + foreach ($test['values'] as $value) { + $series->set($key, $value); + } + $expected[\strtolower($key)] = true; + $result = $series->getAllKeys(); + $this->assertEquals(array_keys($expected), $result); + } + + } } diff --git a/tests/KeyValue/SingleTest.php b/tests/KeyValue/SingleTest.php index 0157260..dd1c182 100644 --- a/tests/KeyValue/SingleTest.php +++ b/tests/KeyValue/SingleTest.php @@ -81,7 +81,7 @@ public function getGroupingSet($testSet) $singleValue->set($key, $value); $expected_value = $value; // we expect the last value set } - $expected[] = array('grouping' => $testGroup, 'key' => \strtolower($key), 'value' => $expected_value); + $expected[] = array('key' => \strtolower($key), 'value' => $expected_value); } $result = $singleValue->getGroupingSet(); @@ -267,9 +267,9 @@ public function delete() * @dataProvider nonUniqueKeyDataProvider * @throws \Exception */ - public function uniqueKeys($testSet) + public function uniqueKeysCheck($testSet) { - $testGroup = 'SingleUniqueKeys'; + $testGroup = 'SeriesUniqueKeys'; $single = Single::create($testGroup, self::$connection); $expected = array(); foreach ($testSet as $test) {