Skip to content

Commit

Permalink
Merge pull request #44 from laminas/3.5.x-merge-up-into-3.6.x_rJdgStH4
Browse files Browse the repository at this point in the history
Merge release 3.5.2 into 3.6.x
  • Loading branch information
snapshotpl authored Dec 3, 2021
2 parents 2347c84 + c867b1a commit 52f3e58
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://github.com/laminas/laminas-test/workflows/Continuous%20Integration/badge.svg)](https://github.com/laminas/laminas-test/actions?query=workflow%3A"Continuous+Integration")

laminas-test provides tools to facilitate unit testing of your Laminas
laminas-test provides tools to facilitate integration testing of your Laminas
Framework applications. At this time, we offer facilities to enable testing of
your Laminas MVC applications. [PHPUnit](https://phpunit.de/) is the only
library supported currently.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "laminas/laminas-test",
"description": "Tools to facilitate unit testing of laminas-mvc applications",
"description": "Tools to facilitate integration testing of laminas-mvc applications",
"license": "BSD-3-Clause",
"keywords": [
"laminas",
Expand Down
2 changes: 1 addition & 1 deletion docs/book/assertions.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Assertions

Assertions are at the heart of unit testing; you use them to verify that the
Assertions are at the heart of testing; you use them to verify that the
results are what you expect. To this end, `Laminas\Test\PHPUnit\AbstractControllerTestCase`
provides a number of assertions to make testing your MVC apps and controllers
simpler.
Expand Down
12 changes: 0 additions & 12 deletions docs/book/index.html

This file was deleted.

2 changes: 1 addition & 1 deletion docs/book/intro.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Introduction

laminas-test provides tools to facilitate unit testing of your
laminas-test provides tools to facilitate integration testing of your
[laminas-mvc](https://docs.laminas.dev/laminas-mvc/) applications.

PHPUnit is the only library supported currently.
2 changes: 1 addition & 1 deletion docs/book/phpunit.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Unit testing with PHPUnit
# Integration Testing with PHPUnit

`Laminas\Test\PHPUnit` provides an abstract `TestCase` for laminas-mvc applications
that contains assertions for testing against a variety of responsibilities.
Expand Down
4 changes: 2 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ site_dir: docs/html
nav:
- Home: index.md
- Introduction: intro.md
- "Unit testing with PHPUnit": phpunit.md
- "Integration testing with PHPUnit": phpunit.md
- Assertions: assertions.md
site_name: laminas-test
site_description: laminas-test
site_description: "Tools to facilitate integration testing of laminas-mvc applications"
repo_url: 'https://github.com/laminas/laminas-test'
extra:
project: MVC
3 changes: 2 additions & 1 deletion src/PHPUnit/Constraint/IsCurrentModuleNameConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public function getCurrentModuleName(): string
$applicationConfig = $this->getTestCase()->getApplicationConfig();

// Find Module from Controller
/** @var string $appModules */
foreach ($applicationConfig['modules'] as $appModules) {
if (strpos($controllerClass, $appModules) !== false) {
if (strpos($controllerClass, $appModules . '\\') !== false) {
if (strpos($appModules, '\\') !== false) {
$match = ltrim(substr($appModules, strrpos($appModules, '\\')), '\\');
} else {
Expand Down
25 changes: 25 additions & 0 deletions test/PHPUnit/Controller/AbstractControllerTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use function array_diff;
use function array_key_exists;
use function array_merge_recursive;
use function count;
use function extension_loaded;
use function get_class;
Expand Down Expand Up @@ -192,6 +193,30 @@ public function testAssertModuleNameWithNamespace()
$this->assertModuleName('TestModule');
}

/** @return void */
public function testAssertModuleWithSimilarName()
{
$applicationConfig = $this->getApplicationConfig();

$testConfig = [
'modules' => [
'ModuleWithSimilarName\TestModule',
'ModuleWithSimilarName\Test',
],
'module_listener_options' => [
'module_paths' => [
'ModuleWithSimilarName\TestModule' => __DIR__ . '/../../_files/ModuleWithSimilarName/TestModule/',
'ModuleWithSimilarName\Test' => __DIR__ . '/../../_files/ModuleWithSimilarName/Test/',
],
],
];

$this->setApplicationConfig(array_merge_recursive($testConfig, $applicationConfig));

$this->dispatch('/similar-name-2-test');
$this->assertModuleName('TestModule');
}

/** @return void */
public function testAssertExceptionDetailsPresentWhenTraceErrorIsEnabled()
{
Expand Down
35 changes: 35 additions & 0 deletions test/_files/ModuleWithSimilarName/Test/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* @see https://github.com/laminas/laminas-test for the canonical source repository
*/

namespace ModuleWithSimilarName\Test;

use Laminas\Loader\StandardAutoloader;

class Module
{
/**
* @psalm-return array<string, mixed>
*/
public function getConfig(): array
{
return include __DIR__ . '/config/module.config.php';
}

/**
* @return string[][][]
* @psalm-return array<string, array<string, array<string, string>>>
*/
public function getAutoloaderConfig(): array
{
return [
StandardAutoloader::class => [
'namespaces' => [
__NAMESPACE__ => __DIR__ . '/src/',
],
],
];
}
}
23 changes: 23 additions & 0 deletions test/_files/ModuleWithSimilarName/Test/config/module.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

return [
'router' => [
'routes' => [
'similar_name_route' => [
'type' => 'literal',
'options' => [
'route' => '/similar-name-test',
'defaults' => [
'controller' => 'similar_name_index',
'action' => 'unittests',
],
],
],
],
],
'controllers' => [
'invokables' => [
'similar_name_index' => 'ModuleWithSimilarName\Test\Controller\IndexController',
],
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* @see https://github.com/laminas/laminas-test for the canonical source repository
*/

namespace ModuleWithSimilarName\Test\Controller;

use Laminas\Mvc\Controller\AbstractActionController;

class IndexController extends AbstractActionController
{
public function unittestsAction(): string
{
return 'unittest';
}
}
35 changes: 35 additions & 0 deletions test/_files/ModuleWithSimilarName/TestModule/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* @see https://github.com/laminas/laminas-test for the canonical source repository
*/

namespace ModuleWithSimilarName\TestModule;

use Laminas\Loader\StandardAutoloader;

class Module
{
/**
* @psalm-return array<string, mixed>
*/
public function getConfig(): array
{
return include __DIR__ . '/config/module.config.php';
}

/**
* @return string[][][]
* @psalm-return array<string, array<string, array<string, string>>>
*/
public function getAutoloaderConfig(): array
{
return [
StandardAutoloader::class => [
'namespaces' => [
__NAMESPACE__ => __DIR__ . '/src/',
],
],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

return [
'router' => [
'routes' => [
'similar_name_2_route' => [
'type' => 'literal',
'options' => [
'route' => '/similar-name-2-test',
'defaults' => [
'controller' => 'similar_name_2_index',
'action' => 'unittests',
],
],
],
],
],
'controllers' => [
'invokables' => [
'similar_name_2_index' => 'ModuleWithSimilarName\TestModule\Controller\IndexController',
],
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* @see https://github.com/laminas/laminas-test for the canonical source repository
*/

namespace ModuleWithSimilarName\TestModule\Controller;

use Laminas\Mvc\Controller\AbstractActionController;

class IndexController extends AbstractActionController
{
public function unittestsAction(): string
{
return 'unittest';
}
}

0 comments on commit 52f3e58

Please sign in to comment.