Skip to content

Commit

Permalink
more fuckery
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaEstes committed Nov 17, 2023
1 parent fdd6560 commit 29e7bfd
Show file tree
Hide file tree
Showing 22 changed files with 106 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/docs/coverage/
/docs/infection/
/site/
vendor/
/.php-cs-fixer.cache
Expand All @@ -10,3 +11,4 @@ phpunit.xml
composer.phar
packages.json
results.sarif
infection.log
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ test-clock: phpunit
test-cqrs: PHPUNIT_TESTSUITE=cqrs
test-cqrs: phpunit

test-http-factory: PHPUNIT_TESTSUITE=http-factory
test-http-factory: phpunit

test-link: PHPUNIT_TESTSUITE=link
test-link: phpunit

Expand Down Expand Up @@ -165,6 +168,13 @@ php-cs-fixer-upgrade:
testdox: ## Run tests and output testdox
XDEBUG_MODE=off $(PHP) -dxdebug.mode=off $(PHPUNIT) --testdox

infection:
XDEBUG_MODE=develop \
$(PHP) \
-dxdebug.mode=develop \
-dapc.enable_cli=1 \
tools/infection/vendor/bin/infection --debug -vvv --show-mutations

tools-install: psalm-install php-cs-fixer-install phpunit-install

tools-upgrade: psalm-upgrade php-cs-fixer-upgrade phpunit-upgrade
Expand Down
26 changes: 26 additions & 0 deletions infection.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "https://raw.githubusercontent.com/infection/infection/0.27.8/resources/schema.json",
"source": {
"directories": [
"."
],
"excludes": [
"docs",
"tools",
"vendor",
"Tests"
]
},
"mutators": {
"@default": true
},
"logs": {
"html": "docs/infection/index.html"
},
"phpUnit": {
"configDir": ".",
"customPath": "tools\/phpunit\/vendor\/bin\/phpunit"
},
"testFrameworkOptions": "--testsuite=all",
"initialTestsPhpOptions": "-dxdebug.mode=coverage -dapc.enable_cli=1"
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
</testsuite>
</testsuites>

<coverage includeUncoveredFiles="true" pathCoverage="true" ignoreDeprecatedCodeUnits="true" disableCodeCoverageIgnore="true">
<coverage includeUncoveredFiles="true" pathCoverage="false" ignoreDeprecatedCodeUnits="true" disableCodeCoverageIgnore="true">
</coverage>

<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class Msg extends AbstractMessage {}

/**
* @coversDefaultClass \SonsOfPHP\Bridge\Symfony\EventSourcing\Message\MessageNormalizer
*
Expand Down Expand Up @@ -40,7 +38,8 @@ public function testItWillNormalizeMessage(): void
{
$normalizer = new MessageNormalizer();

$message = Msg::new();
$message = new class extends AbstractMessage {
};

$this->assertTrue($normalizer->supportsNormalization($message));

Expand All @@ -49,30 +48,4 @@ public function testItWillNormalizeMessage(): void
$this->assertArrayHasKey('payload', $output);
$this->assertArrayHasKey('metadata', $output);
}

/**
* @covers ::denormalize
* @covers ::supportsDenormalization
*/
public function testItWillDenormalizeMessage(): void
{
$normalizer = new MessageNormalizer();

$data = [
'payload' => [
'unit' => 'test',
],
'metadata' => [
'test' => 'unit',
],
];
$type = Msg::class;

$this->assertTrue($normalizer->supportsDenormalization($data, $type));

$output = $normalizer->denormalize($data, $type);

$this->assertSame('test', $output->getPayload()['unit']);
$this->assertSame('unit', $output->getMetadata()['test']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace SonsOfPHP\Component\Cqrs;

use SonsOfPHP\Contract\Cqrs\CommandMessageHandlerInterface;

/**
* @author Joshua Estes <joshua@sonsofphp.com>
*/
Expand Down
2 changes: 2 additions & 0 deletions src/SonsOfPHP/Component/Cqrs/AbstractQueryMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace SonsOfPHP\Component\Cqrs;

use SonsOfPHP\Contract\Cqrs\QueryMessageHandlerInterface;

/**
* @author Joshua Estes <joshua@sonsofphp.com>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use SonsOfPHP\Component\EventSourcing\Message\Repository\MessageRepositoryInterface;
use SonsOfPHP\Component\EventSourcing\Tests\FakeAggregate;

class Msg extends AbstractMessage {}

/**
* @coversDefaultClass \SonsOfPHP\Component\EventSourcing\Aggregate\Repository\AggregateRepository
*
Expand Down Expand Up @@ -70,7 +68,7 @@ public function testPersistWillUseEventDispatcher(): void

$aggregate = new FakeAggregate('unique-id');

$message = Msg::new();
$message = new class extends AbstractMessage {};
$aggregate->raiseThisEvent($message);

$repository->persist($aggregate);
Expand All @@ -90,7 +88,7 @@ public function testPersistAndFind(): void

$aggregate = new FakeAggregate('unique-id');

$message = Msg::new();
$message = new class extends AbstractMessage {};
$aggregate->raiseThisEvent($message);

$repository->persist($aggregate);
Expand All @@ -113,7 +111,7 @@ public function testPersistAndFindWithoutUsingAggregateId(): void

$aggregate = new FakeAggregate('unique-id');

$message = Msg::new();
$message = new class extends AbstractMessage {};
$aggregate->raiseThisEvent($message);

$repository->persist($aggregate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
use SonsOfPHP\Component\EventSourcing\Message\MessageInterface;
use SonsOfPHP\Component\EventSourcing\Metadata;

class Msg extends AbstractMessage {}

/**
* @coversDefaultClass \SonsOfPHP\Component\EventSourcing\Message\AbstractMessage
*
Expand All @@ -31,7 +29,7 @@ final class AbstractMessageTest extends TestCase
*/
public function testItHasTheRightInterface(): void
{
$message = Msg::new();
$message = $this->createMock(AbstractMessage::class);

$this->assertInstanceOf(MessageInterface::class, $message);
}
Expand All @@ -41,7 +39,7 @@ public function testItHasTheRightInterface(): void
*/
public function testGetMetadataHasEmptyArraryAsDefaultValue(): void
{
$message = Msg::new();
$message = $this->createMock(AbstractMessage::class)::new();

$this->assertCount(6, $message->getMetadata());
}
Expand All @@ -51,7 +49,7 @@ public function testGetMetadataHasEmptyArraryAsDefaultValue(): void
*/
public function testWithMetadataReturnsNewStatic(): void
{
$message = Msg::new();
$message = $this->createMock(AbstractMessage::class)::new();

$return = $message->withMetadata([
Metadata::EVENT_TYPE => 'test',
Expand All @@ -64,7 +62,8 @@ public function testWithMetadataReturnsNewStatic(): void
*/
public function testWithMetadataWorksCorrectly(): void
{
$message = Msg::new()->withMetadata([
$message = $this->createMock(AbstractMessage::class);
$message = $message::new()->withMetadata([
Metadata::EVENT_TYPE => 'test',
]);

Expand All @@ -81,7 +80,7 @@ public function testWithMetadataWorksCorrectly(): void
*/
public function testGettersWithEmptyMetadata(): void
{
$message = Msg::new();
$message = $this->createMock(AbstractMessage::class)::new();

$this->expectException(EventSourcingException::class);
$this->assertSame('', $message->getEventId());
Expand All @@ -103,7 +102,8 @@ public function testGettersWithEmptyMetadata(): void
*/
public function testGettersWithMetadata(): void
{
$message = Msg::new()->withMetadata([
$message = $this->createMock(AbstractMessage::class);
$message = $message::new()->withMetadata([
Metadata::EVENT_ID => 'event-id',
Metadata::EVENT_TYPE => 'event.type',
Metadata::TIMESTAMP => '2022-04-20',
Expand All @@ -126,7 +126,8 @@ public function testGettersWithMetadata(): void
*/
public function testGetAggregateIdReturnsCorrectInterface(): void
{
$message = Msg::new()->withMetadata([
$message = $this->createMock(AbstractMessage::class);
$message = $message::new()->withMetadata([
Metadata::AGGREGATE_ID => 'aggregate-id',
]);

Expand All @@ -139,7 +140,8 @@ public function testGetAggregateIdReturnsCorrectInterface(): void
*/
public function testGetAggregateVersionReturnsCorrectInterface(): void
{
$message = Msg::new()->withMetadata([
$message = $this->createMock(AbstractMessage::class);
$message = $message::new()->withMetadata([
Metadata::AGGREGATE_VERSION => 123,
]);

Expand All @@ -151,7 +153,7 @@ public function testGetAggregateVersionReturnsCorrectInterface(): void
*/
public function testGetPayloadHasEmptyArraryAsDefaultValue(): void
{
$message = Msg::new();
$message = $this->createMock(AbstractMessage::class)::new();

$this->assertCount(0, $message->getPayload());
}
Expand All @@ -161,7 +163,7 @@ public function testGetPayloadHasEmptyArraryAsDefaultValue(): void
*/
public function testWithPayloadReturnsNewStatic(): void
{
$message = Msg::new();
$message = $this->createMock(AbstractMessage::class)::new();

$return = $message->withPayload([
'key' => 'val',
Expand All @@ -174,7 +176,8 @@ public function testWithPayloadReturnsNewStatic(): void
*/
public function testWithPayloadWorksCorrectly(): void
{
$message = Msg::new()->withPayload([
$message = $this->createMock(AbstractMessage::class);
$message = $message::new()->withPayload([
'key' => 'val',
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SonsOfPHP\Component\EventSourcing\Tests\Message;
namespace SonsOfPHP\Component\EventSourcing\Tests\Message\Enricher;

use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\EventSourcing\Message\Enricher\Handler\NullMessageEnricherHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SonsOfPHP\Component\Filesystem\Tests;
namespace SonsOfPHP\Component\Filesystem\Tests\Adapter;

use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SonsOfPHP\Component\Filesystem\Tests;
namespace SonsOfPHP\Component\Filesystem\Tests\Adapter;

use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SonsOfPHP\Component\Filesystem\Tests;
namespace SonsOfPHP\Component\Filesystem\Tests\Adapter;

use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SonsOfPHP\Component\Filesystem\Tests;
namespace SonsOfPHP\Component\Filesystem\Tests\Adapter;

use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SonsOfPHP\Component\Filesystem\Tests;
namespace SonsOfPHP\Component\Filesystem\Tests\Adapter;

use PHPUnit\Framework\MockObject;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace SonsOfPHP\Component\Filesystem\Tests;
namespace SonsOfPHP\Component\Filesystem\Tests\Adapter;

use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/SonsOfPHP/Component/HttpFactory/HttpFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class HttpFactory implements RequestFactoryInterface
{
use RequestFactoryTrait;
use ResponseFactoryTrait;
use ServerResponseFactoryTrait;
use ServerRequestFactoryTrait;
use StreamFactoryTrait;
use UploadedFileFactoryTrait;
use UriFactoryTrait;
Expand Down
15 changes: 12 additions & 3 deletions src/SonsOfPHP/Component/HttpFactory/Tests/ResponseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

/**
* @coversDefaultClass \SonsOfPHP\Component\HttpFactory\ResponseFactory
* @uses \SonsOfPHP\Component\HttpMessage\Response
*/
final class ResponseFactoryTest extends TestCase
{
Expand All @@ -23,13 +24,21 @@ public function testItImplementsCorrectInterface(): void
}

/**
* @dataProvider validCreateResponseProvider
*
* @covers ::createResponse
* @uses \SonsOfPHP\Component\HttpMessage\Response
*/
public function testCreateResponseWorksAsExpected(): void
public function testCreateResponseWorksAsExpected(int $code, string $reasonPhrase): void
{
$factory = new ResponseFactory();

$this->assertInstanceOf(ResponseInterface::class, $factory->createResponse());
$this->assertInstanceOf(ResponseInterface::class, $factory->createResponse($code, $reasonPhrase));
}

public static function validCreateResponseProvider(): iterable
{
yield [200, 'OK'];
yield [201, 'Not Content'];
yield [404, 'Not Found'];
}
}
Loading

0 comments on commit 29e7bfd

Please sign in to comment.