Skip to content

Commit 6efd3f8

Browse files
author
Willem Wigman
committed
Add test-skeleton files and first simple test to validate module is enabled
1 parent 5a8a154 commit 6efd3f8

File tree

7 files changed

+214
-0
lines changed

7 files changed

+214
-0
lines changed

.gitattributes

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/composer.json export-ignore
4+
/.travis.yml export-ignore
5+
/.travis export-ignore
6+
/tests export-ignore
7+
/auth.json export-ignore

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor

.travis.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
sudo: required
2+
dist: trusty
3+
group: edge
4+
addons:
5+
apt:
6+
packages:
7+
- mysql-server-5.6
8+
- mysql-client-core-5.6
9+
- mysql-client-5.6
10+
- postfix
11+
hosts:
12+
- magento2.travis
13+
language: php
14+
matrix:
15+
include:
16+
- php: 7.2
17+
env:
18+
- MAGENTO_VERSION=2.3
19+
- TEST_SUITE=integration
20+
- php: 7.2
21+
env:
22+
- MAGENTO_VERSION=2.4-develop
23+
- TEST_SUITE=integration
24+
- php: 7.1
25+
env:
26+
- MAGENTO_VERSION=2.3
27+
- TEST_SUITE=integration
28+
- php: 7.1
29+
env:
30+
- MAGENTO_VERSION=2.4-develop
31+
- TEST_SUITE=integration
32+
env:
33+
global:
34+
- COMPOSER_BIN_DIR=~/bin
35+
- COMPOSER_PACKAGE_NAME=integer-net/magento2-global-custom-layout
36+
cache:
37+
apt: true
38+
directories:
39+
- $HOME/.composer/cache
40+
before_script: ./.travis/before_script.sh
41+
script: phpunit -c magento2/dev/tests/$TEST_SUITE --coverage-text --coverage-clover=/tmp/coverage.clover
42+
after_script:
43+
- |
44+
wget https://scrutinizer-ci.com/ocular.phar
45+
php ocular.phar code-coverage:upload --format=php-clover /tmp/coverage.clover

.travis/before_script.sh

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
trap '>&2 echo Error: Command \`$BASH_COMMAND\` on line $LINENO failed with exit code $?' ERR
5+
6+
# mock mail
7+
sudo service postfix stop
8+
echo # print a newline
9+
smtp-sink -d "%d.%H.%M.%S" localhost:2500 1000 &
10+
echo 'sendmail_path = "/usr/sbin/sendmail -t -i "' > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/sendmail.ini
11+
12+
# adjust memory limit
13+
echo 'memory_limit = -1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
14+
phpenv rehash;
15+
16+
composer selfupdate
17+
18+
# clone main magento github repository
19+
git clone --branch $MAGENTO_VERSION --depth=1 https://github.com/magento/magento2
20+
21+
# install Magento
22+
cd magento2
23+
24+
# add composer package under test, composer require will trigger update/install
25+
composer config minimum-stability dev
26+
composer config repositories.travis_to_test git https://github.com/$TRAVIS_REPO_SLUG.git
27+
#TODO make it work with tags as well:
28+
composer require ${COMPOSER_PACKAGE_NAME}:dev-${TRAVIS_BRANCH}\#{$TRAVIS_COMMIT}
29+
30+
# prepare for test suite
31+
case $TEST_SUITE in
32+
integration)
33+
cp vendor/$COMPOSER_PACKAGE_NAME/tests/Integration/phpunit.xml.dist dev/tests/integration/phpunit.xml
34+
35+
cd dev/tests/integration
36+
37+
# create database and move db config into place
38+
mysql -uroot -e '
39+
SET @@global.sql_mode = NO_ENGINE_SUBSTITUTION;
40+
CREATE DATABASE magento_integration_tests;
41+
'
42+
cp etc/install-config-mysql.travis.php.dist etc/install-config-mysql.php
43+
sed -i '/amqp/d' etc/install-config-mysql.php
44+
45+
cd ../../..
46+
;;
47+
unit)
48+
cp vendor/$COMPOSER_PACKAGE_NAME/tests/Unit/phpunit.xml.dist dev/tests/unit/phpunit.xml
49+
;;
50+
esac

auth.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"http-basic": {
3+
"repo.magento.com": {
4+
"username": "438956769d577f67f247510ffa624225",
5+
"password": "b5d1664bb6ee2d27ec75dd36d6a2ac4e"
6+
}
7+
}
8+
}

tests/Integration/ModuleTest.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace IntegerNet\GlobalCustomLayout\Test\Integration;
5+
6+
use Magento\Framework\App\ObjectManager;
7+
use Magento\Framework\Module\ModuleList;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class ModuleTest extends TestCase
11+
{
12+
private const MODULE_NAME = 'IntegerNet_GlobalCustomLayout';
13+
14+
/**
15+
* @var ObjectManager
16+
*/
17+
private $objectManager;
18+
19+
protected function setUp()
20+
{
21+
$this->objectManager = ObjectManager::getInstance();
22+
}
23+
24+
public function testModuleIsActive()
25+
{
26+
/** @var ModuleList $moduleList */
27+
$moduleList = $this->objectManager->create(ModuleList::class);
28+
$this->assertTrue(
29+
$moduleList->has(self::MODULE_NAME),
30+
sprintf('The module %s should be enabled', self::MODULE_NAME)
31+
);
32+
}
33+
}

tests/Integration/phpunit.xml.dist

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd"
10+
colors="true"
11+
beStrictAboutTestsThatDoNotTestAnything="false"
12+
bootstrap="./framework/bootstrap.php"
13+
stderr="true"
14+
>
15+
<!-- Test suites definition -->
16+
<testsuites>
17+
<testsuite name="GlobalCustomLayout Integration Tests">
18+
<directory suffix="Test.php">../../../vendor/integer-net/magento2-global-custom-layout/tests/Integration</directory>
19+
</testsuite>
20+
</testsuites>
21+
<!-- Code coverage filters -->
22+
<filter>
23+
<whitelist addUncoveredFilesFromWhiteList="true">
24+
<directory suffix=".php">../../../vendor/integer-net/magento2-global-custom-layout/src</directory>
25+
</whitelist>
26+
</filter>
27+
<!-- PHP INI settings and constants definition -->
28+
<php>
29+
<includePath>.</includePath>
30+
<includePath>testsuite</includePath>
31+
<ini name="date.timezone" value="America/Los_Angeles"/>
32+
<ini name="xdebug.max_nesting_level" value="200"/>
33+
<!-- Local XML configuration file ('.dist' extension will be added, if the specified file doesn't exist) -->
34+
<const name="TESTS_INSTALL_CONFIG_FILE" value="etc/install-config-mysql.php"/>
35+
<!-- Local XML configuration file ('.dist' extension will be added, if the specified file doesn't exist) -->
36+
<const name="TESTS_GLOBAL_CONFIG_FILE" value="etc/config-global.php"/>
37+
<!-- Semicolon-separated 'glob' patterns, that match global XML configuration files -->
38+
<const name="TESTS_GLOBAL_CONFIG_DIR" value="../../../app/etc"/>
39+
<!-- Whether to cleanup the application before running tests or not -->
40+
<!--<const name="TESTS_CLEANUP" value="enabled"/>-->
41+
<const name="TESTS_CLEANUP" value="enabled" />
42+
<!-- Memory usage and estimated leaks thresholds -->
43+
<!--<const name="TESTS_MEM_USAGE_LIMIT" value="1024M"/>-->
44+
<const name="TESTS_MEM_LEAK_LIMIT" value=""/>
45+
<!-- Whether to output all CLI commands executed by the bootstrap and tests -->
46+
<!--<const name="TESTS_EXTRA_VERBOSE_LOG" value="1"/>-->
47+
<!-- Path to Percona Toolkit bin directory -->
48+
<!--<const name="PERCONA_TOOLKIT_BIN_DIR" value=""/>-->
49+
<!-- CSV Profiler Output file -->
50+
<!--<const name="TESTS_PROFILER_FILE" value="profiler.csv"/>-->
51+
<!-- Bamboo compatible CSV Profiler Output file name -->
52+
<!--<const name="TESTS_BAMBOO_PROFILER_FILE" value="profiler.csv"/>-->
53+
<!-- Metrics for Bamboo Profiler Output in PHP file that returns array -->
54+
<!--<const name="TESTS_BAMBOO_PROFILER_METRICS_FILE" value="../../build/profiler_metrics.php"/>-->
55+
<!-- Whether to output all CLI commands executed by the bootstrap and tests -->
56+
<const name="TESTS_EXTRA_VERBOSE_LOG" value="1"/>
57+
<!-- Magento mode for tests execution. Possible values are "default", "developer" and "production". -->
58+
<const name="TESTS_MAGENTO_MODE" value="developer"/>
59+
<!-- Minimum error log level to listen for. Possible values: -1 ignore all errors, and level constants form http://tools.ietf.org/html/rfc5424 standard -->
60+
<const name="TESTS_ERROR_LOG_LISTENER_LEVEL" value="-1"/>
61+
<!-- Connection parameters for MongoDB library tests -->
62+
<!--<const name="MONGODB_CONNECTION_STRING" value="mongodb://localhost:27017"/>-->
63+
<!--<const name="MONGODB_DATABASE_NAME" value="magento_integration_tests"/>-->
64+
</php>
65+
<!-- Test listeners -->
66+
<listeners>
67+
<listener class="Magento\TestFramework\Event\PhpUnit"/>
68+
<listener class="Magento\TestFramework\ErrorLog\Listener"/>
69+
</listeners>
70+
</phpunit>

0 commit comments

Comments
 (0)