Skip to content

Commit 7a15b78

Browse files
committed
MAGECLOUD-1495: Add Proper Logging for Variables Overrides
1 parent 3a8a3e6 commit 7a15b78

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/Process/Build/DeployStaticContent/Generate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function execute()
7070
try {
7171
$locales = $this->buildOption->getLocales();
7272
$excludeThemes = $this->buildOption->getExcludedThemes();
73-
$threadCount= $this->buildOption->getThreadCount();
73+
$threadCount = $this->buildOption->getThreadCount();
7474

7575
$logMessage = 'Generating static content for locales: ' . implode(' ', $locales);
7676

src/StaticContent/ThreadCountOptimizer.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\MagentoCloud\StaticContent;
77

8+
use Psr\Log\LoggerInterface;
9+
810
class ThreadCountOptimizer
911
{
1012
/**
@@ -19,6 +21,19 @@ class ThreadCountOptimizer
1921
*/
2022
const THREAD_COUNT_COMPACT_STRATEGY = 1;
2123

24+
/**
25+
* @var LoggerInterface
26+
*/
27+
private $logger;
28+
29+
/**
30+
* @param LoggerInterface $logger
31+
*/
32+
public function __construct(LoggerInterface $logger)
33+
{
34+
$this->logger = $logger;
35+
}
36+
2237
/**
2338
* Defines best thread count value based on deploy strategy name
2439
*
@@ -29,6 +44,12 @@ class ThreadCountOptimizer
2944
public function optimize(int $threads, string $strategy): int
3045
{
3146
if ($strategy === self::STRATEGY_COMPACT) {
47+
if ($threads !== self::THREAD_COUNT_COMPACT_STRATEGY) {
48+
$this->logger->notice(
49+
'Threads count was forced to 1 as compact strategy can\'t be run with more than one job'
50+
);
51+
}
52+
3253
return self::THREAD_COUNT_COMPACT_STRATEGY;
3354
}
3455

src/Test/Unit/StaticContent/ThreadCountOptimizerTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\MagentoCloud\StaticContent\ThreadCountOptimizer;
99
use PHPUnit\Framework\TestCase;
10+
use PHPUnit_Framework_MockObject_MockObject as Mock;
11+
use Psr\Log\LoggerInterface;
1012

1113
class ThreadCountOptimizerTest extends TestCase
1214
{
@@ -15,9 +17,16 @@ class ThreadCountOptimizerTest extends TestCase
1517
*/
1618
private $optimizer;
1719

20+
/**
21+
* @var LoggerInterface|Mock
22+
*/
23+
private $loggerMock;
24+
1825
protected function setUp()
1926
{
20-
$this->optimizer = new ThreadCountOptimizer();
27+
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
28+
29+
$this->optimizer = new ThreadCountOptimizer($this->loggerMock);
2130
}
2231

2332
/**
@@ -57,4 +66,16 @@ public function optimizeDataProvider(): array
5766
]
5867
];
5968
}
69+
70+
public function testOptimizeWithNotice()
71+
{
72+
$this->loggerMock->expects($this->once())
73+
->method('notice')
74+
->with('Threads count was forced to 1 as compact strategy can\'t be run with more than one job');
75+
76+
$this->assertEquals(
77+
1,
78+
$this->optimizer->optimize(3, ThreadCountOptimizer::STRATEGY_COMPACT)
79+
);
80+
}
6081
}

0 commit comments

Comments
 (0)