Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
19e79ad4
Commit
19e79ad4
authored
Dec 04, 2014
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Plain `echo` replaced by `stdout()` at `yii\console\AssetController`
parent
70ca76d4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
21 deletions
+56
-21
AssetController.php
framework/console/controllers/AssetController.php
+16
-15
AssetControllerTest.php
...nit/framework/console/controllers/AssetControllerTest.php
+12
-6
StdOutBufferControllerTrait.php
...ework/console/controllers/StdOutBufferControllerTrait.php
+28
-0
No files found.
framework/console/controllers/AssetController.php
View file @
19e79ad4
...
...
@@ -144,14 +144,14 @@ class AssetController extends Controller
$bundles
=
$this
->
loadBundles
(
$this
->
bundles
);
$targets
=
$this
->
loadTargets
(
$this
->
targets
,
$bundles
);
foreach
(
$targets
as
$name
=>
$target
)
{
echo
"Creating output bundle '
{
$name
}
':
\n
"
;
$this
->
stdout
(
"Creating output bundle '
{
$name
}
':
\n
"
)
;
if
(
!
empty
(
$target
->
js
))
{
$this
->
buildTarget
(
$target
,
'js'
,
$bundles
);
}
if
(
!
empty
(
$target
->
css
))
{
$this
->
buildTarget
(
$target
,
'css'
,
$bundles
);
}
echo
"
\n
"
;
$this
->
stdout
(
"
\n
"
)
;
}
$targets
=
$this
->
adjustDependency
(
$targets
,
$bundles
);
...
...
@@ -165,7 +165,7 @@ class AssetController extends Controller
*/
protected
function
loadConfiguration
(
$configFile
)
{
echo
"Loading configuration from '
{
$configFile
}
'...
\n
"
;
$this
->
stdout
(
"Loading configuration from '
{
$configFile
}
'...
\n
"
)
;
foreach
(
require
(
$configFile
)
as
$name
=>
$value
)
{
if
(
property_exists
(
$this
,
$name
)
||
$this
->
canSetProperty
(
$name
))
{
$this
->
$name
=
$value
;
...
...
@@ -184,7 +184,7 @@ class AssetController extends Controller
*/
protected
function
loadBundles
(
$bundles
)
{
echo
"Collecting source bundles information...
\n
"
;
$this
->
stdout
(
"Collecting source bundles information...
\n
"
)
;
$am
=
$this
->
getAssetManager
();
$result
=
[];
...
...
@@ -324,7 +324,7 @@ class AssetController extends Controller
*/
protected
function
adjustDependency
(
$targets
,
$bundles
)
{
echo
"Creating new bundle configuration...
\n
"
;
$this
->
stdout
(
"Creating new bundle configuration...
\n
"
)
;
$map
=
[];
foreach
(
$targets
as
$name
=>
$target
)
{
...
...
@@ -423,7 +423,7 @@ EOD;
if
(
!
file_put_contents
(
$bundleFile
,
$bundleFileContent
))
{
throw
new
Exception
(
"Unable to write output bundle configuration at '
{
$bundleFile
}
'."
);
}
echo
"Output bundle configuration created at '
{
$bundleFile
}
'.
\n
"
;
$this
->
stdout
(
"Output bundle configuration created at '
{
$bundleFile
}
'.
\n
"
)
;
}
/**
...
...
@@ -437,14 +437,14 @@ EOD;
if
(
empty
(
$inputFiles
))
{
return
;
}
echo
" Compressing JavaScript files...
\n
"
;
$this
->
stdout
(
" Compressing JavaScript files...
\n
"
)
;
if
(
is_string
(
$this
->
jsCompressor
))
{
$tmpFile
=
$outputFile
.
'.tmp'
;
$this
->
combineJsFiles
(
$inputFiles
,
$tmpFile
);
echo
shell_exec
(
strtr
(
$this
->
jsCompressor
,
[
$this
->
stdout
(
shell_exec
(
strtr
(
$this
->
jsCompressor
,
[
'{from}'
=>
escapeshellarg
(
$tmpFile
),
'{to}'
=>
escapeshellarg
(
$outputFile
),
]));
]))
)
;
@
unlink
(
$tmpFile
);
}
else
{
call_user_func
(
$this
->
jsCompressor
,
$this
,
$inputFiles
,
$outputFile
);
...
...
@@ -452,7 +452,7 @@ EOD;
if
(
!
file_exists
(
$outputFile
))
{
throw
new
Exception
(
"Unable to compress JavaScript files into '
{
$outputFile
}
'."
);
}
echo
" JavaScript files compressed into '
{
$outputFile
}
'.
\n
"
;
$this
->
stdout
(
" JavaScript files compressed into '
{
$outputFile
}
'.
\n
"
)
;
}
/**
...
...
@@ -466,14 +466,14 @@ EOD;
if
(
empty
(
$inputFiles
))
{
return
;
}
echo
" Compressing CSS files...
\n
"
;
$this
->
stdout
(
" Compressing CSS files...
\n
"
)
;
if
(
is_string
(
$this
->
cssCompressor
))
{
$tmpFile
=
$outputFile
.
'.tmp'
;
$this
->
combineCssFiles
(
$inputFiles
,
$tmpFile
);
echo
shell_exec
(
strtr
(
$this
->
cssCompressor
,
[
$this
->
stdout
(
shell_exec
(
strtr
(
$this
->
cssCompressor
,
[
'{from}'
=>
escapeshellarg
(
$tmpFile
),
'{to}'
=>
escapeshellarg
(
$outputFile
),
]));
]))
)
;
@
unlink
(
$tmpFile
);
}
else
{
call_user_func
(
$this
->
cssCompressor
,
$this
,
$inputFiles
,
$outputFile
);
...
...
@@ -481,7 +481,7 @@ EOD;
if
(
!
file_exists
(
$outputFile
))
{
throw
new
Exception
(
"Unable to compress CSS files into '
{
$outputFile
}
'."
);
}
echo
" CSS files compressed into '
{
$outputFile
}
'.
\n
"
;
$this
->
stdout
(
" CSS files compressed into '
{
$outputFile
}
'.
\n
"
)
;
}
/**
...
...
@@ -656,7 +656,8 @@ EOD;
if
(
!
file_put_contents
(
$configFile
,
$template
))
{
throw
new
Exception
(
"Unable to write template file '
{
$configFile
}
'."
);
}
else
{
echo
"Configuration file template created at '
{
$configFile
}
'.
\n\n
"
;
$this
->
stdout
(
"Configuration file template created at '
{
$configFile
}
'.
\n\n
"
);
return
self
::
EXIT_CODE_NORMAL
;
}
}
...
...
tests/unit/framework/console/controllers/AssetControllerTest.php
View file @
19e79ad4
...
...
@@ -62,12 +62,12 @@ class AssetControllerTest extends TestCase
/**
* Creates test asset controller instance.
* @return AssetController
* @return AssetController
Mock
*/
protected
function
createAssetController
()
{
$module
=
$this
->
getMock
(
'yii\\base\\Module'
,
[
'fake'
],
[
'console'
]);
$assetController
=
new
AssetController
(
'asset'
,
$module
);
$assetController
=
new
AssetController
Mock
(
'asset'
,
$module
);
$assetController
->
interactive
=
false
;
$assetController
->
jsCompressor
=
'cp {from} {to}'
;
$assetController
->
cssCompressor
=
'cp {from} {to}'
;
...
...
@@ -84,11 +84,8 @@ class AssetControllerTest extends TestCase
protected
function
runAssetControllerAction
(
$actionID
,
array
$args
=
[])
{
$controller
=
$this
->
createAssetController
();
ob_start
();
ob_implicit_flush
(
false
);
$controller
->
run
(
$actionID
,
$args
);
return
ob_get_clean
();
return
$controller
->
flushStdOutBuffer
();
}
/**
...
...
@@ -457,3 +454,11 @@ EOL;
$this
->
assertEquals
(
$expectedRealPath
,
$realPath
);
}
}
/**
* Mock class for [[\yii\console\controllers\AssetController]]
*/
class
AssetControllerMock
extends
AssetController
{
use
StdOutBufferControllerTrait
;
}
\ No newline at end of file
tests/unit/framework/console/controllers/StdOutBufferControllerTrait.php
0 → 100644
View file @
19e79ad4
<?php
namespace
yiiunit\framework\console\controllers
;
/**
* StdOutBufferControllerTrait is a trait, which can be applied to [[yii\console\Controller]],
* allowing to store all output into internal buffer instead of direct sending it to 'stdout'
*/
trait
StdOutBufferControllerTrait
{
/**
* @var string output buffer.
*/
private
$stdOutBuffer
=
''
;
public
function
stdout
(
$string
)
{
$this
->
stdOutBuffer
.=
$string
;
}
public
function
flushStdOutBuffer
()
{
$result
=
$this
->
stdOutBuffer
;
$this
->
stdOutBuffer
=
''
;
return
$result
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment