Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Feature/zend test load module #3942

Closed
wants to merge 9 commits into from
Closed

Feature/zend test load module #3942

wants to merge 9 commits into from

Conversation

blanchonvincent
Copy link
Contributor

The goal is to have an helper for write unit tests on module :

@blanchonvincent
Copy link
Contributor Author

@Ocramius can read this PR ? thank you :)

use Zend\ServiceManager\ServiceManager;
use Zend\Stdlib\Exception;

abstract class ModuleLoader extends PHPUnit_Framework_TestCase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why abstract? And why extending a PHPUnit_Framework_TestCase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look my unit test, the goal was provide a "loadModule" method with direct assertion without usage of "new"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blanchonvincent perfectly clear what the intent was, I think that isn't an optimal approach (especially since it's an util, not a test case).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius agree with you, it was just a draft :) i will change that

@Ocramius
Copy link
Member

Ocramius commented Mar 3, 2013

@blanchonvincent the idea looks good so far, BUT there's way too much public API in my opinion.

You should probably have something like:

  • __construct($modules, $modulePaths) (or $applicationConfig)
  • getServiceManager()
  • getModuleManager()
  • getApplication()

No other public API is needed in my opinion (that's already probably too much) :)

Usage would be:

class MyTest extends PHPUnit_Framework_TestCase
{
    public function testFoo()
    {
        $moduleLoader = new \Zend\Test\PHPUnit\Util\ModuleLoader(array(
            'modules' => array('Application')
        ));

        $this->assertInstanceOf(
            'Zend\ServiceManager\ServiceLocatorInterface',
            $moduleLoader->getServiceManager()
        );
        $this->assertInstanceOf(
            'Zend\ModuleManager\ModuleManager',
            $moduleLoader->getModuleManager()
        );
        $this->assertInstanceOf(
            'Zend\Mvc\ApplicationInterface',
            $moduleLoader->getApplication()
        );
    }
}

@blanchonvincent
Copy link
Contributor Author

@Ocramius I did not know if I had to make a external class (like you) or internal class with PHPUnit_Framework_TestCase integrated (like me).
Your solution look more natural and easy to understand for new user.

@Ocramius
Copy link
Member

Ocramius commented Mar 3, 2013

@blanchonvincent it's not really about ease of use... I'm mainly thinking of something that doesn't enforce inheritance from another test case (we got so many already :( )

@blanchonvincent
Copy link
Contributor Author

@Ocramius yeah, you are right

@Ocramius
Copy link
Member

Ocramius commented Mar 3, 2013

@blanchonvincent ping again once you think you've sorted it out, and thank you for picking this =)

@blanchonvincent
Copy link
Contributor Author

@Ocramius second draft, look better, i will add unit tests again later

}
$configuration = array(
'module_listener_options' => array(
'module_paths' => $modulesPath,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As before: if a module is provided as name => path, then the module manager should already be able to handle that :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius if you write in your config :

'modules' => array(
    'Foo' => '/path/to/my/foo',
),

?

Currently in "modules" key, only name is accepted : https://github.com/zendframework/zf2/blob/master/library/Zend/ModuleManager/ModuleManager.php#L80

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EvanDotPro ping?

@Ocramius
Copy link
Member

Ocramius commented Mar 3, 2013

Looks much better, thank you! :)

@ghost ghost assigned weierophinney Mar 8, 2013
@weierophinney
Copy link
Member

@blanchonvincent I tried merging, but I'm missing the file tests/ZendTest/Test/_files/cache/module-config-cache.phpunit.php (notified in ModuleLoaderTest::testCanLoadModulesFromConfig).

@blanchonvincent
Copy link
Contributor Author

@weierophinney you must only create the "cache" directory in "tests/ZendTest/Test/_files/". I add the directory in the versioning.

@weierophinney
Copy link
Member

@blanchonvincent Do not write files inside the tests directory; write them to the system temporary directory. (We need to do this in part to allow developers to run the test suite when installed via their system package manager; if we write inside the tests directory, they may not have permissions. Plus, it's cleaner.)

@blanchonvincent
Copy link
Contributor Author

@weierophinney sorry, i changed with the system temporary directory.

@weierophinney
Copy link
Member

@blanchonvincent I ran into issues running the test suite multiple times, as the test suite is not cleaning out the cache files. Interestingly, when I implemented that logic... a new test started failing consistently, AbstractControllerTestCaseTest::testApplicationClassAndTestRestoredConsoleFlag now fails on the very first assertion of Console::isConsole. Trying to track it down...

weierophinney added a commit that referenced this pull request Mar 12, 2013
weierophinney added a commit that referenced this pull request Mar 12, 2013
- Clears module cache files on setup and teardown
weierophinney added a commit that referenced this pull request Mar 12, 2013
- trailing whitespace, braces
weierophinney added a commit that referenced this pull request Mar 12, 2013
@weierophinney
Copy link
Member

Tracked it down, and all tests are running. Thanks, @blanchonvincent -- merged to develop for release with 2.2.0.

@Ocramius
Copy link
Member

👍!

@blanchonvincent
Copy link
Contributor Author

@weierophinney @Ocramius Thank you both for your work

weierophinney added a commit to zendframework/zend-test that referenced this pull request May 15, 2015
…ent/feature/zend-test-load-module

Feature/zend test load module
weierophinney added a commit to zendframework/zend-test that referenced this pull request May 15, 2015
- Clears module cache files on setup and teardown
weierophinney added a commit to zendframework/zend-test that referenced this pull request May 15, 2015
- trailing whitespace, braces
weierophinney added a commit to zendframework/zend-test that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants