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

assertSeeInOrder does not actually assert anything #23592

Closed
Jantho1990 opened this issue Mar 18, 2018 · 0 comments
Closed

assertSeeInOrder does not actually assert anything #23592

Jantho1990 opened this issue Mar 18, 2018 · 0 comments

Comments

@Jantho1990
Copy link
Contributor

Jantho1990 commented Mar 18, 2018

  • Laravel Version: 5.6.12
  • PHP Version: 7.2

$response->assertSeeInOrder does not actually assert anything, but instead calls PHPUnit::fail() if the conditions are not met. This causes tests which only have that assertion to be reported as "risky".

public function assertSeeInOrder(array $values)
    {
        $position = 0;

        foreach ($values as $value) {
            $valuePosition = mb_strpos($this->getContent(), $value, $position);

            if ($valuePosition === false || $valuePosition < $position) {
                PHPUnit::fail(
                    'Failed asserting that \''.$this->getContent().
                    '\' contains "'.$value.'" in specified order.'
                );
            }

            $position = $valuePosition + mb_strlen($value);
        }

        return $this;
    }

// A test which only uses this assertion will be reported as "risky" by PHPUnit because of not running any assertions.
public function canViewAlbumTitleFromBandView()
    {
        $band = factory(Band::class)->create();
        $album = factory(Album::class)->create([
            'band_id' => $band->id
        ]);

        // visit the page
        $response = $this->get("/bands/$band->id");

        // assert we can see the data
        $response->assertSeeInOrder(['Albums:', $album->name]);
    }

Yes, in my case I could just write different assertions that would assert reliably, but isn't this bad practice to be including built-in custom assertions that don't actually assert anything? Shouldn't we be able to write a custom assertion class instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant