Skip to content
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

PHPUnit - fix to assertCount #3750

Closed
SpacePossum opened this issue May 14, 2018 · 2 comments
Closed

PHPUnit - fix to assertCount #3750

SpacePossum opened this issue May 14, 2018 · 2 comments

Comments

@SpacePossum
Copy link
Contributor

A few years back there was an issue with assertCount when using an iterator on HHVM (sebastianbergmann/phpunit#1413), as such we don't fix asserts in PHPUnit tests like;

$this->assertSame(1, count($a));

Since than;

  • less projects support HHVM (we dropped it here as well)
  • HHVM and PHPUnit improved over time
  • we have add a way to add a configuration option to fix this conditionally

Therefor I suggest to add it.

@keradus
Copy link
Member

keradus commented May 15, 2018

I believe that this was not an configuration for fixer that we decided to not fix, but we actually not have fixer capable to do it out of the box, by just adjusting the config (like internal list of methods, not settings exposed to end-user) of it.

@SpacePossum
Copy link
Contributor Author

just leaving my notes on this here;

// When testing var vs. constant the constant is assumed the expected one,
// if testing with both arguments the left one is assumed the expected one

// assertTrue($a == 1) assertTrue(1 == $a)
    // assertEquals(1, $a)

// assertTrue($a == $b)
    // assertEquals($a, $b)

// assertTrue($a != 1) assertTrue(1 != $a)
    // assertNotEquals(1, $a)

// assertTrue($a != $b)
    // assertNotEquals($a, $b)

// assertTrue($a === 1) assertTrue(1 === $a)
    // assetSame(1, $a)

// assertTrue($a !== 1) assertTrue(1 !== $a)
    // assetNotSame(1, $a)

// assertTrue($a > 1)
    // assertGreaterThan(1, $a)

// assertTrue(1 > $a)
    // assertLessThan(1, $a)

// assertTrue($a >= 1)
    // assertGreaterThanOrEqual(1, $a)

// assertTrue(1 >= $a)
    // assertLessThanOrEqual(1, $a)

// assertTrue($a < 1)
    //assertLessThan(1, $a)

// assertTrue(1 < $a)
    //assertGreaterThan(1, $a)

// assertTrue($a <= 1)
    //assertLessThanOrEqual(1, $a)

// assertTrue(1 <= $a)
    // assertGreaterThanOrEqual(1, $a)

// assertTrue(count($a) == 1) assertTrue(1 == count($a))
// assertTrue(count($a) === 1) assertTrue(1 === count($a))
    // assertCount(1, $a)

// assertTrue(count($a) != 1) assertTrue(1 != count($a))
// assertTrue(count($a) !== 1) assertTrue(1 !== count($a))
    // assertNotCount(1, $a)

// assertTrue(\count($a) == ++$b + 9)
    // assertCount(++$b + 9, $a)

// for cases above; equivalent for `assertFalse`
// preserve comments and deal with spacing
// preserve the `$message` part

keradus added a commit that referenced this issue Jun 2, 2018
…acePossum)

This PR was squashed before being merged into the 2.12-dev branch (closes #3785).

Discussion
----------

PhpUnitDedicateAssertFixer - fix to assertCount too

closes #3750

```
            'assert same' => [
                '<?php $this->assertCount(1, $a);',
                '<?php $this->assertSame(1, count($a));',
            ],
```

for more example please see the tests

Commits
-------

cf8221b PhpUnitDedicateAssertFixer - fix to assertCount too
@keradus keradus closed this as completed Jun 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants