Skip to content

Commit

Permalink
Remove YII_ENV.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Oct 21, 2023
1 parent b748818 commit f58eb36
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
11 changes: 6 additions & 5 deletions framework/console/controllers/ServeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ public function actionIndex($address = 'localhost')
$command .= " -r \"{$router}\"";
}

if (YII_ENV === 'test') {
return true;
}

passthru($command);
$this->runCommand($command);
}

/**
Expand Down Expand Up @@ -132,4 +128,9 @@ protected function isAddressTaken($address)
fclose($fp);
return true;
}

protected function runCommand($command)

Check warning on line 132 in framework/console/controllers/ServeController.php

View check run for this annotation

Codecov / codecov/patch

framework/console/controllers/ServeController.php#L132

Added line #L132 was not covered by tests
{
passthru($command);
}

Check warning on line 135 in framework/console/controllers/ServeController.php

View check run for this annotation

Codecov / codecov/patch

framework/console/controllers/ServeController.php#L134-L135

Added lines #L134 - L135 were not covered by tests
}
41 changes: 35 additions & 6 deletions tests/framework/console/controllers/ServeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ public function testAddressTaken()
/** @var ServeController $serveController */
$serveController = $this->getMockBuilder(ServeControllerMocK::className())
->setConstructorArgs(['serve', Yii::$app])
->setMethods(['isAddressTaken'])
->setMethods(['isAddressTaken', 'runCommand'])
->getMock();

$serveController->expects($this->once())->method('isAddressTaken')->willReturn(true);
$serveController->expects($this->never())->method('runCommand');

$serveController->docroot = $docroot;
$serveController->port = 8080;
Expand All @@ -48,14 +49,21 @@ public function testAddressTaken()
$this->assertContains('http://localhost:8080 is taken by another process.', $result);
}

public function testDefautlValues()
public function testDefaultValues()
{
$docroot = __DIR__ . '/stub';

$serveController = new ServeControllerMock('serve', Yii::$app);
/** @var ServeController $serveController */
$serveController = $this->getMockBuilder(ServeControllerMock::className())
->setConstructorArgs(['serve', Yii::$app])
->setMethods(['runCommand'])
->getMock();

$serveController->docroot = $docroot;
$serveController->port = 8080;

$serveController->expects($this->once())->method('runCommand')->willReturn(true);

ob_start();
$serveController->actionIndex();
ob_end_clean();
Expand All @@ -71,9 +79,16 @@ public function testDoocRootWithNoExistValue()
{
$docroot = '/not/exist/path';

$serveController = new ServeControllerMock('serve', Yii::$app);
/** @var ServeController $serveController */
$serveController = $this->getMockBuilder(ServeControllerMock::className())
->setConstructorArgs(['serve', Yii::$app])
->setMethods(['runCommand'])
->getMock();

$serveController->docroot = $docroot;

$serveController->expects($this->any())->method('runCommand')->willReturn(true);

ob_start();
$serveController->actionIndex();
ob_end_clean();
Expand All @@ -88,11 +103,18 @@ public function testWithRouterNoExistValue()
$docroot = __DIR__ . '/stub';
$router = '/not/exist/path';

$serveController = new ServeControllerMock('serve', Yii::$app);
/** @var ServeController $serveController */
$serveController = $this->getMockBuilder(ServeControllerMock::className())
->setConstructorArgs(['serve', Yii::$app])
->setMethods(['runCommand'])
->getMock();

$serveController->docroot = $docroot;
$serveController->port = 8081;
$serveController->router = $router;

$serveController->expects($this->any())->method('runCommand')->willReturn(true);

ob_start();
$serveController->actionIndex();
ob_end_clean();
Expand All @@ -107,11 +129,18 @@ public function testWithRouterValue()
$docroot = __DIR__ . '/stub';
$router = __DIR__ . '/stub/index.php';

$serveController = new ServeControllerMock('serve', Yii::$app);
/** @var ServeController $serveController */
$serveController = $this->getMockBuilder(ServeControllerMock::className())
->setConstructorArgs(['serve', Yii::$app])
->setMethods(['runCommand'])
->getMock();

$serveController->docroot = $docroot;
$serveController->port = 8081;
$serveController->router = $router;

$serveController->expects($this->once())->method('runCommand')->willReturn(true);

ob_start();
$serveController->actionIndex();
ob_end_clean();
Expand Down

0 comments on commit f58eb36

Please sign in to comment.