{"record":{"id":"744751135986c4b4","repo":"pestphp/pest","slug":"expecting-s-not-s-s","errorCode":null,"errorMessage":"Expecting %s not %s %s.","messagePattern":"Expecting (.+?) not (.+?) (.+?)\\.","errorType":"exception","errorClass":"ExpectationFailedException","httpStatus":null,"severity":"error","filePath":"src/Expectations/OppositeExpectation.php","lineNumber":670,"sourceCode":"\n            $this->original->{$name}; // @phpstan-ignore-line\n        } catch (ExpectationFailedException) {\n            return $this->original;\n        }\n\n        $this->throwExpectationFailedException($name);\n    }\n\n    /**\n     * @param  array<int, mixed>|string  $arguments\n     */\n    public function throwExpectationFailedException(string $name, array|string $arguments = []): never\n    {\n        $arguments = is_array($arguments) ? $arguments : [$arguments];\n\n        $exporter = Exporter::default();\n\n        throw new ExpectationFailedException(sprintf(\n            'Expecting %s not %s %s.',\n            $exporter->shortenedExport($this->original->value),\n            strtolower((string) preg_replace('/(?<!\\ )[A-Z]/', ' $0', $name)),\n            implode(' ', array_map(fn (mixed $argument): string => $exporter->export($argument), $arguments)),\n        ));\n    }\n\n    public function toHaveConstructor(): ArchExpectation\n    {\n        return $this->toHaveMethod('__construct');\n    }\n\n    public function toHaveDestructor(): ArchExpectation\n    {\n        return $this->toHaveMethod('__destruct');\n    }\n\n    private function toBeBackedEnum(string $backingType): ArchExpectation","sourceCodeStart":652,"sourceCodeEnd":688,"githubUrl":"https://github.com/pestphp/pest/blob/1af74a215c3a89bc7a44fc6f9322e369eaad2423/src/Expectations/OppositeExpectation.php#L652-L688","documentation":"This is the runtime assertion failure raised by negated expectations: when you chain ->not (or use a toNot* method), the opposite expectation succeeds only if the underlying assertion FAILS. If the value actually satisfies the expectation, Pest throws ExpectationFailedException with 'Expecting {value} not {assertion} {args}.' — i.e., the test proved the opposite of what you asserted.","triggerScenarios":"expect($count)->not->toBe(0) when $count is 0; expect($response->status())->not->toBe(200) on a successful response; ->not->toContain('error') when the string does contain 'error'; ->not->toBeNull() applied to a null value.","commonSituations":"Guard assertions (asserting an error did NOT occur) that fire because the error did occur; negative assertions written optimistically; copy-pasting a not from another test; values changing type after refactors (0 == null style surprises with toBeFalse/not->toBeTrue pairs).","solutions":["Read the message: it names the value, the negated assertion, and the arguments — that tells you exactly which expectation failed; then fix the code under test so the negation actually holds.","If the value is legitimately expected to match, the assertion itself is wrong: remove ->not or turn it into the positive form (toBe instead of not->toBe).","For status/guard checks, prefer the most specific negated assertion available (not->toBeEmpty, not->toBeNull) over broad ones (not->toBe) to make failures actionable."],"exampleFix":"// before\nit('does not log errors', function () {\n    expect($this->logger->lines)->not->toBeEmpty(); // failed: Expecting [...] not to be empty.\n});\n// after\nit('does not log errors', function () {\n    expect($this->logger->lines)->toBeEmpty();\n});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"use PHPUnit\\Framework\\ExpectationFailedException;\n\nit('assertion actually fails as expected', function () {\n    try {\n        expect($value)->not->toBeEmpty();\n        $this->fail('Negated expectation should have failed');\n    } catch (ExpectationFailedException $e) {\n        // expected path — the value WAS empty\n        expect($e->getMessage())->toContain('not to be empty');\n    }\n});","preventionTips":["Prefer the most specific negated assertion (not->toBeNull, not->toContain) over broad ones (not->toBe) so failures are actionable.","When writing guard assertions, first assert the happy path failed: check the error state before asserting its absence.","Keep negated assertions close to the act that produced the value — long chains hide which ->not failed."],"tags":["pest","expectation","assertion-failure","negation","not"],"backgroundTag":"test-assertion-failed","analyzedSha":"1af74a215c3a89bc7a44fc6f9322e369eaad2423","analyzedAt":"2026-08-21T02:16:38.132Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}