From 23062bdcc0d63746b2a2c245d1e41e2d12deed34 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Thu, 14 Sep 2017 14:24:44 +0300 Subject: [PATCH] Tests are our examples, using images as test material --- example/example.php | 73 -------------------------- src/ivuorinen/Palette/Palette.php | 3 -- tests/PaletteTest.php | 15 ++++++ {example => tests/assets}/example.gif | Bin {example => tests/assets}/example.jpg | Bin {example => tests/assets}/example.png | Bin 6 files changed, 15 insertions(+), 76 deletions(-) delete mode 100644 example/example.php rename {example => tests/assets}/example.gif (100%) rename {example => tests/assets}/example.jpg (100%) rename {example => tests/assets}/example.png (100%) diff --git a/example/example.php b/example/example.php deleted file mode 100644 index 0148399..0000000 --- a/example/example.php +++ /dev/null @@ -1,73 +0,0 @@ -Full process (creates palette, saves to same dir as palette.php)\n"; -foreach ($testimages_full_process as $image) { - - // Initiation with image triggers Palette::run() - $test = new \ivuorinen\Palette\Palette($image); - - echo "
"
-       . "Processing {$test->filename}\n"
-       . print_r($test->colorsArray, true)
-       . "
\n"; -} - -echo "

Controlled process

\n"; -foreach ($testimages_controlled_process as $image) { - $test = new \ivuorinen\Palette\Palette(); - - // We set the image, precision and amount of colors to return - $test->filename = $image; // Full, or relative path to our image - $test->precision = 10; // Bigger is faster, smaller returns more colors - $test->returnColors = 5; // How many colors we want in our array at most - - // Configure your destination file name fully we get - // an array encoded to json, so .json extension is good choice - $test->destination = dirname(__FILE__) . '/' . md5($test->filename) . '.json'; - - echo "
"
-       . "Processing {$test->filename}\n";
-
-    if (is_readable($test->destination)) {
-
-        echo "Returning data from cache: {$test->destination}\n";
-
-        // We have already processed these files, return the array
-        // from cached version to make everything work faster
-        $colors = json_decode(file_get_contents($test->destination));
-
-    } else {
-
-        echo "Processing data and saving to {$test->destination}\n";
-
-        // We don't have cached versions so process colors as an array
-        $colors = $test->getPalette();
-
-        // And then save the data to file specified in $test->destination
-        $test->save();
-
-    }
-
-    echo print_r($colors, true)
-       . "
\n"; - -} - -echo "

This one fails

\n"; -$test = new \ivuorinen\Palette\Palette('/bin/sh'); diff --git a/src/ivuorinen/Palette/Palette.php b/src/ivuorinen/Palette/Palette.php index 25775d5..dcc2fc7 100644 --- a/src/ivuorinen/Palette/Palette.php +++ b/src/ivuorinen/Palette/Palette.php @@ -28,8 +28,6 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * - * @category Default - * @package Palette * @author Ismo Vuorinen * @license http://www.opensource.org/licenses/mit-license.php MIT License * @copyright 2013 Ismo Vuorinen @@ -44,7 +42,6 @@ namespace ivuorinen\Palette; * @author Ismo Vuorinen * @license http://www.opensource.org/licenses/mit-license.php MIT License * @link https://github.com/ivuorinen/palette - * @example example/example.php Usage examples **/ class Palette { diff --git a/tests/PaletteTest.php b/tests/PaletteTest.php index b36b82b..abb0af0 100644 --- a/tests/PaletteTest.php +++ b/tests/PaletteTest.php @@ -30,6 +30,21 @@ class PaletteTest extends \PHPUnit_Framework_TestCase } } + public function test_known_images_with_many_colors() + { + $location = __DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR; + $images = ['example.gif', 'example.jpg', 'example.png']; + + foreach ($images as $imageFile) { + $image = $location . $imageFile; + $this->assertFileExists($image); + + $palette = new \ivuorinen\Palette\Palette($image); + $this->assertCount(10, $palette->colorsArray); + $this->assertEquals($image, $palette->filename); + } + } + public function test_failure_no_image() { $palette = new \ivuorinen\Palette\Palette(''); diff --git a/example/example.gif b/tests/assets/example.gif similarity index 100% rename from example/example.gif rename to tests/assets/example.gif diff --git a/example/example.jpg b/tests/assets/example.jpg similarity index 100% rename from example/example.jpg rename to tests/assets/example.jpg diff --git a/example/example.png b/tests/assets/example.png similarity index 100% rename from example/example.png rename to tests/assets/example.png