Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data directly without checking paths #359

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,21 @@ 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.
*
* @return static
*/
public function addData( $path, $content ) {
$this->data[ $path ] = $content;

return $this;
}

/**
* Minify the data & (optionally) saves it to a file.
*
* @param string[optional] $path Path to write the data to
Expand Down
13 changes: 13 additions & 0 deletions tests/js/JSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down