Skip to content

Commit

Permalink
PHPUnit 6.0 & PSR-4 refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lastzero committed Feb 4, 2017
1 parent d20e7c4 commit 8769a67
Show file tree
Hide file tree
Showing 68 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -31,7 +31,7 @@
"phpunit/phpunit": ">=6.0"
},
"autoload": {
"psr-0": { "TestTools\\": "src/" }
"psr-4": { "TestTools\\": "src/" }
},
"config": {
"bin-dir": "bin/"
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Expand Up @@ -13,15 +13,15 @@
>
<testsuites>
<testsuite>
<directory>src/*/Tests</directory>
<directory>src/Tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
<exclude>
<directory>src/*/Tests</directory>
<directory>src/Tests</directory>
</exclude>
</whitelist>
</filter>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -18,8 +18,7 @@ public function testBasePath () {

public function testFixturePath () {
$result = $this->getFixturePath();
$this->assertEquals(36, strpos(strrev($result), strrev('TestTools')));
$this->assertEquals(21, strpos(strrev($result), strrev('_fixture')));
$this->assertStringEndsWith('src/Tests/_fixtures/Fixture/FileFixture', $result);
}

public function testFilterAlphanumeric () {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -17,7 +17,7 @@ class UnitTestCaseTest extends UnitTestCase
public function testGetFixturePath()
{
$fixturePath = $this->getContainer()->getParameter('fixture.path') . '/';
$this->assertStringEndsWith('src/TestTools/Tests/_fixtures/TestCase/UnitTestCase/', $fixturePath);
$this->assertStringEndsWith('src/Tests/_fixtures/TestCase/UnitTestCase/', $fixturePath);

$buzz = $this->get('buzz.fixture');
$this->assertInstanceOf('TestTools\Buzz\Client', $buzz);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

7 comments on commit 8769a67

@TomasVotruba
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome PR! :)

@TomasVotruba
Copy link
Contributor

@TomasVotruba TomasVotruba commented on 8769a67 Feb 4, 2017

Choose a reason for hiding this comment

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

Just wondering, proper place for test is /tests directory. The more you are going for PSR-4 now.

This is more standard for most packages:

/src
/tests
composer.json

I recall we had similar discussion, but now I see you are upgrading to new packages and architecture pattern, so I think this would go very well along.

@TomasVotruba
Copy link
Contributor

@TomasVotruba TomasVotruba commented on 8769a67 Feb 4, 2017

Choose a reason for hiding this comment

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

Just a preview: https://github.com/TomasVotruba/test-tools/pull/1/files

It would make even phpunit.xml.dist configuration bit more readable :)

@lastzero
Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks for reaching out again on this matter. My goal is not to do things the same as the mass, but to do it better if possible. Having a common namespace, just to put things in different root directories and then use the autoloader to bring it together again doesn't make a lot of sense to me. For example, you need much more vertical space in the file browser of your favourite IDE to see both trees at the same time. A major inconvenience. Having a separate directory can make sense, if the tests are too big to ship, like it is the case with Doctrine. It's how it started, but in 2017 it's ok to have the tests as part of your regular source. Coding itself is so complex, so finding the tests directory should be a very easy task for a developer, especially since a Tests directory is also standard for Symfony, easily the most popular PHP framework out there.

@TomasVotruba
Copy link
Contributor

@TomasVotruba TomasVotruba commented on 8769a67 Feb 5, 2017

Choose a reason for hiding this comment

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

Symfony is very slow in adapting good practice, be aware of that. It makes sense, because it's the oldest and most spread PHP framework and it can't afford to make many changes (opposed to much younger Laravel).

I didn't realize it before studying other frameworks and making my own set of packages and applying them to various frameworks.

If you are open to "non-Symfony-way", but PHP-way, feel free to find inspiration here:

It's how it started, but in 2017 it's ok to have the tests as part of your regular source.

Never the case. There is no benefit in slowing down production code by tests, when speed is important more than ever to get customer's attention.

@lastzero
Copy link
Owner Author

Choose a reason for hiding this comment

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

Symfony is not the oldest PHP framework - actually it's quite young (I started using PHP in 1998) and especially the DI concept of Symfony 2 was a major step forward for the PHP community. Thank you for the links, I'm going to read them :)

Since I will always ship my code with tests, using a different directory will not make the code slower or faster. Not shipping with tests might make a difference, but I doubt it can be measured. If you come up with bold claims like that, I want to see some facts like a benchmark.

@TomasVotruba
Copy link
Contributor

Choose a reason for hiding this comment

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

Times flies slow, even Laravel is old framework for me now :D Not in the age number, but architectural concepts it was and is build on.

What is the oldest used PHP framework then?

As for DI. Symfony promoted constructor injection only, which is like using DI on 20 % of it's maximum power and doesn't save almost any time and influence architecture. It was actually Nette that introduced DI with constructor autowiring:

(they're in Czech, but Google Translator should do)

Please sign in to comment.