2017 © Pedro Peláez
 

library magerun2-test-framework

Test-Framework for n98-magerun2 commands

image

n98/magerun2-test-framework

Test-Framework for n98-magerun2 commands

  • Monday, October 3, 2016
  • by cmuench
  • Repository
  • 2 Watchers
  • 0 Stars
  • 218 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

n98-magerun2 Test Framework

This package contains some PHPUnit test cases., (*1)

Prerequisite

The test runner requires a vanilla Magento 2 installation. To run test suite it's necessary to set the environment variable N98_MAGERUN2_TEST_MAGENTO_ROOT with the root path to the installation., (*2)

All unit tests run against this installation. Please don't use any production environment!, (*3)

Test Module Commands

Example Test Case:, (*4)

loadConfigFile(__DIR__ . '/../../n98-magerun2.yaml');

        /**
         * Test if command could be found
         */
        $command = $this->getApplication()->find('foo');

        /**
         * Call command
         */
        $commandTester = new CommandTester($command);
        $commandTester->execute(
            [
            ]
        );
    }
}
```


## Test dev:console Commands

### Code-Generating Command

Create a reference file which contains the content of the code generator.
In the following test case the file is place in "__DIR__ /_files/ExampleSomething.php".

The method `mockWriterFileWriteFileAssertion` of the TestCase class mocks the module writer and compares the output against the reference file.

```php
createCommandTester($command);
        $command->setCurrentModuleName('Acme_Example');

        $writerMock = $this->mockWriterFileWriteFileAssertion(
            __DIR__ . '/_files/ExampleSomething.php'
        );

        $command->setCurrentModuleDirectoryWriter($writerMock);
        $commandTester->execute([
            /* pass your parameters */
        ]);
    }
}
```

## Run PHPUnit Tests

```bash
N98_MAGERUN2_TEST_MAGENTO_ROOT=/path/to/magento/root ./vendor/bin/phpunit
```

## Example PHPUnit Configuration

Example module structure:

```plain
.
├── README.md
├── composer.json
├── n98-magerun2.yaml
├── phpunit.xml.dist
├── src
│   └── Command
│       └── ExampleCommand.php
└── tests
    └── Command
        └── ExampleCommandTest.php
```

### phpunit.xml.dist

```xml

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         bootstrap="vendor/autoload.php"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
  <coverage includeUncoveredFiles="true">
    <include>
      <directory>src</directory>
    </include>
  </coverage>
  <testsuites>
    <testsuite name="n98-magerun2 Project Transfer Tools Commands">
      <directory>tests</directory>
    </testsuite>
  </testsuites>
</phpunit>

composer.json

{
  "name": "acme/example",
  "description": "Some commands",  
  "require-dev": {
    "n98/magerun2": "^4",
    "n98/magerun2-test-framework": "^2",
    "phpunit/phpunit": "^9"
  },
  "autoload-dev": {
    "psr-4": {
      "Acme\\Example\\": "tests"
    }
  },
  "autoload": {
    "psr-4": {
      "Acme\\Example\\": "src"
    }
  }
}

The Versions

03/10 2016

dev-master

9999999-dev http://netz98.github.com/n98-magerun2/

Test-Framework for n98-magerun2 commands

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Christian Münch

phpunit magento magerun2

03/10 2016

1.1.0

1.1.0.0 http://netz98.github.com/n98-magerun2/

Test-Framework for n98-magerun2 commands

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Christian Münch

phpunit magento magerun2

02/10 2016

1.0.2

1.0.2.0 http://netz98.github.com/n98-magerun2/

Test-Framework for n98-magerun2 commands

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Christian Münch

phpunit magento magerun2

02/10 2016

1.0.1

1.0.1.0 http://netz98.github.com/n98-magerun2/

Test-Framework for n98-magerun2 commands

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Christian Münch

phpunit magento magerun2

02/10 2016

1.0.0

1.0.0.0 http://netz98.github.com/n98-magerun2/

Test-Framework for n98-magerun2 commands

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Christian Münch

phpunit magento magerun2