Skip to content

[PhpUnitBridge] Make ClockMock match namespaces that begin with Tests\\ #18726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

teohhanhui
Copy link
Contributor

@teohhanhui teohhanhui commented May 9, 2016

Q A
Branch? 2.8
Bug fix? yes?
New feature? no
BC breaks? no?
Deprecations? no
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR symfony/symfony-docs#6546

See symfony/symfony-standard#969

@teohhanhui
Copy link
Contributor Author

/cc @nicolas-grekas

$count = 0;
$ns = preg_replace('/(^|\\\\)Tests\\\\/', '$1', $mockedNs[0], 1, $count);
if (1 === $count) {
$mockedNs[] = $ns;
Copy link
Member

Choose a reason for hiding this comment

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

imho we should simply additionally check if the namespace starts with Tests\:

if (false !== strpos($class, '\\Tests\\')) {
    // ...
} elseif (0 === strpos('Tests\\')) {
    $mockedNs[] = substr($class, 6);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using regex seems more extensible to me, even though it might not be as readable...

Copy link
Member

Choose a reason for hiding this comment

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

I'd favor readability here, thus @xabbuh proposal

@teohhanhui
Copy link
Contributor Author

@nicolas-grekas: Addressed @xabbuh's comment.

$testNs = substr($class, 0, strrpos($class, '\\'));
$mockedNs = array($testNs);
if (false !== ($pos = strpos($testNs, '\\Tests\\'))) {
$mockedNs[] = substr_replace($testNs, '\\', $pos, 7);
Copy link
Member

Choose a reason for hiding this comment

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

this changes the semantic a bit (only the first \Tests\ is replaced now). Let's be safe and keep the code asis for this first part...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't that actually have been a bug? Or was that the intended behaviour?

Copy link
Member

Choose a reason for hiding this comment

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

not a bug (nor really planned but we shouldn't change now)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@teohhanhui teohhanhui force-pushed the mock-tests-ns branch 3 times, most recently from 4b00e01 to 310eaa5 Compare May 27, 2016 14:56
@teohhanhui
Copy link
Contributor Author

I believe Travis failure is unrelated.

$ns = str_replace('\\Tests\\', '\\', $class);
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
} elseif (0 === strpos($class, 'Tests\\')) {
$mockedNs[] = substr($class, 6, strrpos($class, '\\'));
Copy link
Member

Choose a reason for hiding this comment

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

Must be:

$mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6);

@teohhanhui
Copy link
Contributor Author

Status: Needs Review

@xabbuh
Copy link
Member

xabbuh commented May 30, 2016

👍

Status: Reviewed

@nicolas-grekas
Copy link
Member

feature on 3.2 isn't it?

@teohhanhui
Copy link
Contributor Author

feature on 3.2 isn't it?

If so, then we need to address this issue in symfony-standard, because it does not work as expected out of the box.

@nicolas-grekas
Copy link
Member

there is no deps bewteen the bridge and sfstd, so no need to change, just use the newest bridge to run the tests

@teohhanhui
Copy link
Contributor Author

teohhanhui commented May 30, 2016

just use the newest bridge to run the tests

That means bumping the version of the PhpUnit Bridge in symfony-standard 2.8+?

@nicolas-grekas
Copy link
Member

Thank you @teohhanhui.

nicolas-grekas added a commit that referenced this pull request May 30, 2016
…egin with Tests\\ (teohhanhui)

This PR was submitted for the 2.8 branch but it was merged into the 3.2-dev branch instead (closes #18726).

Discussion
----------

[PhpUnitBridge] Make ClockMock match namespaces that begin with Tests\\

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes?
| New feature?  | no
| BC breaks?    | no?
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | symfony/symfony-docs#6546

See symfony/symfony-standard#969

Commits
-------

2630c13 [PhpUnitBridge] Make ClockMock match namespaces that begin with Tests\\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants