From 130d94249c696997d2cbb4b43eba3ff604b76a62 Mon Sep 17 00:00:00 2001 From: Ahmed Saeed Date: Wed, 10 Feb 2021 13:05:39 +0200 Subject: [PATCH 1/3] add new method to add data of path and content without any check --- src/Minify.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Minify.php b/src/Minify.php index 736ff11..f5f34d5 100644 --- a/src/Minify.php +++ b/src/Minify.php @@ -137,7 +137,17 @@ public function addFile($data /* $data = null, ... */) return $this; } - /** + /** + * Add data with path and content without doing any check. + * + * @param string $path File path to be minified. + * @param string $content Content to be minified. + */ + public function addData( $path, $content ) { + $this->data[ $path ] = $content; + } + + /** * Minify the data & (optionally) saves it to a file. * * @param string[optional] $path Path to write the data to From 4eeda08af72a1012202e0dc7d99436f06714b086 Mon Sep 17 00:00:00 2001 From: Ahmed Saeed Date: Wed, 10 Feb 2021 13:54:40 +0200 Subject: [PATCH 2/3] add valid return --- src/Minify.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Minify.php b/src/Minify.php index f5f34d5..8031806 100644 --- a/src/Minify.php +++ b/src/Minify.php @@ -142,9 +142,13 @@ public function addFile($data /* $data = null, ... */) * * @param string $path File path to be minified. * @param string $content Content to be minified. + * + * @return static */ public function addData( $path, $content ) { $this->data[ $path ] = $content; + + return $this; } /** From 7caaa8c9140cd5a8df08ae0b2ceb77ff91705282 Mon Sep 17 00:00:00 2001 From: Ahmed Saeed Date: Wed, 10 Feb 2021 13:54:59 +0200 Subject: [PATCH 3/3] add test case --- tests/js/JSTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/js/JSTest.php b/tests/js/JSTest.php index db43308..c58fbaa 100644 --- a/tests/js/JSTest.php +++ b/tests/js/JSTest.php @@ -41,6 +41,19 @@ public function testAddFile() $this->assertEquals('var test=1', $result); } + /** + * Test minifier addFile method. + */ + public function testAddData() + { + $minifier = $this->mockMinifier(); + $minifier->addData(__DIR__.'/sample/source/script1.js', 'var test_from_addData=1'); + + $result = $minifier->minify(); + + $this->assertEquals('var test_from_addData=1', $result); + } + /** * Test JS minifier rules, provided by dataProvider. *