Skip to content

assertStringStartsWith after assertNotEmpty fails #231

Open
@gisostallenberg

Description

@gisostallenberg

assertStringStartsWith after assertNotEmpty fails with error "Parameter #1 $prefix of method PHPUnit\Framework\Assert::assertStringStartsWith() expects non-empty-string', while the string cannot be empty due to the assertNotEmpty call.

<?php

use PHPUnit\Framework\TestCase;

class FooTest extends TestCase {
    public function testFoo(): void
    {
        $string = ([
            '',
            'bar',
        ])[rand(0, 1)];
        $this->assertNotEmpty($string);
        $this->assertStringStartsWith($string, 'baz');
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions