Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
php: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4]
php: [7.1, 7.2, 7.3, 7.4, 8.0]

steps:
- name: Checkout code
Expand Down
52 changes: 27 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
{
"name":"codeception/module-cli",
"description":"Codeception module for testing basic shell commands and shell output",
"keywords":["codeception"],
"homepage":"http://codeception.com/",
"type":"library",
"license":"MIT",
"authors":[
{
"name":"Michael Bodnarchuk"
}
],
"minimum-stability": "RC",
"require": {
"php": ">=5.6.0 <9.0",
"codeception/codeception": "*@dev"
},
"conflict": {
"codeception/codeception": "<4.0"
},
"autoload":{
"classmap": ["src/"]
},
"config": {
"classmap-authoritative": true
}
"name": "codeception/module-cli",
"description": "Codeception module for testing basic shell commands and shell output",
"keywords": [ "codeception" ],
"homepage": "https://codeception.com/",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Michael Bodnarchuk"
}
],
"minimum-stability": "RC",
"require": {
"php": "^7.1 || ^8.0",
"codeception/codeception": "*@dev"
},
"conflict": {
"codeception/codeception": "<4.0"
},
"autoload": {
"classmap": [
"src/"
]
},
"config": {
"classmap-authoritative": true
}
}
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ A Codeception module for testing basic shell commands and shell output.
[![Total Downloads](https://poser.pugx.org/codeception/module-cli/downloads)](https://packagist.org/packages/codeception/module-cli)
[![License](https://poser.pugx.org/codeception/module-cli/license)](/LICENSE)

## Requirements

* `PHP 7.1` or higher.

## Installation

```
Expand Down
39 changes: 20 additions & 19 deletions src/Codeception/Module/Cli.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

declare(strict_types=1);

namespace Codeception\Module;

use Codeception\Module as CodeceptionModule;
use Codeception\Module;
use Codeception\TestInterface;

/**
Expand All @@ -14,13 +17,16 @@
*
* *Please review the code of non-stable modules and provide patches if you have issues.*
*/
class Cli extends CodeceptionModule
class Cli extends Module
{
/**
* @var string
*/
public $output = '';

public $result = null;
public $result;

public function _before(TestInterface $test)
public function _before(TestInterface $test): void
{
$this->output = '';
}
Expand All @@ -38,9 +44,8 @@ public function _before(TestInterface $test)
* ```
*
* @param $command
* @param bool $failNonZero
*/
public function runShellCommand($command, $failNonZero = true)
public function runShellCommand($command, bool $failNonZero = true): void
{
$data = [];
exec("$command", $data, $resultCode);
Expand All @@ -52,15 +57,15 @@ public function runShellCommand($command, $failNonZero = true)
if ($resultCode !== 0 && $failNonZero) {
\PHPUnit\Framework\Assert::fail("Result code was $resultCode.\n\n" . $this->output);
}
$this->debug(preg_replace('~s/\e\[\d+(?>(;\d+)*)m//g~', '', $this->output));
$this->debug(preg_replace('#s/\e\[\d+(?>(;\d+)*)m//g#', '', $this->output));
}

/**
* Checks that output from last executed command contains text
*
* @param $text
*/
public function seeInShellOutput($text)
public function seeInShellOutput($text): void
{
\Codeception\PHPUnit\TestCase::assertStringContainsString($text, $this->output);
}
Expand All @@ -69,26 +74,22 @@ public function seeInShellOutput($text)
* Checks that output from latest command doesn't contain text
*
* @param $text
*
*/
public function dontSeeInShellOutput($text)
public function dontSeeInShellOutput($text): void
{
$this->debug($this->output);
\Codeception\PHPUnit\TestCase::assertStringNotContainsString($text, $this->output);
}

/**
* @param $regex
*/
public function seeShellOutputMatches($regex)
public function seeShellOutputMatches($regex): void
{
\Codeception\PHPUnit\TestCase::assertRegExp($regex, $this->output);
}

/**
* Returns the output from latest command
*/
public function grabShellOutput()
public function getOutput(): string
{
return $this->output;
}
Expand All @@ -103,9 +104,9 @@ public function grabShellOutput()
*
* @param $code
*/
public function seeResultCodeIs($code)
public function seeResultCodeIs($code): void
{
$this->assertEquals($this->result, $code, "result code is $code");
$this->assertEquals($this->result, $code, sprintf('result code is %s', $code));
}

/**
Expand All @@ -118,8 +119,8 @@ public function seeResultCodeIs($code)
*
* @param $code
*/
public function seeResultCodeIsNot($code)
public function seeResultCodeIsNot($code): void
{
$this->assertNotEquals($this->result, $code, "result code is $code");
$this->assertNotEquals($this->result, $code, sprintf('result code is %s', $code));
}
}
⌂ Proxy