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

[AddDoesNotPerformAssertionToNonAssertingTestRector] Add failing test for Prophecy assertions. #2640

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Rector\PHPUnit\Tests\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector\Fixture;

use Rector\PHPUnit\Tests\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector\Source\Denormalizer;
use Rector\PHPUnit\Tests\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector\Source\DenormalizerInterface;

class SkipProphecyAssertions extends \PHPUnit\Framework\TestCase
{
public function testDenormalize(): void
{
$badData = ['42'];
$fixedData = [42];

$type = 'anything';

/** @var DenormalizerInterface $denormalizer */
$denormalizer = $this->prophesize(DenormalizerInterface::class);
$denormalizer
->denormalize($fixedData, $type)
->shouldBeCalled(); // this is an assertion here

(new Denormalizer($denormalizer))->handle($badData, $type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Rector\PHPUnit\Tests\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector\Source;

final class Denormalizer
{
/**
* @var DenormalizerInterface
*/
private $denormalizer;

public function __construct(DenormalizerInterface $denormalizer)
{
$this->denormalizer = $denormalizer;
}

public function handle(array $data, string $type): ?array
{
try {
return $this->denormalizer->denormalize($data, $type);
} catch (\Throwable $throwable) {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Rector\PHPUnit\Tests\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector\Source;

interface DenormalizerInterface
{
/**
* Denormalizes data back into an object of the given class.
*
* @param mixed $data Data to restore
* @param string $type The expected class to instantiate
* @param string $format Format the given data was extracted from
* @param array $context Options available to the denormalizer
*
* @return object|array
*/
public function denormalize($data, $type, $format = null, array $context = []);
}