Skip to content

Commit

Permalink
Merge pull request #22 from petrknap/ide-test
Browse files Browse the repository at this point in the history
Removed unnecessary notices
  • Loading branch information
petrknap authored May 25, 2024
2 parents 72eedab + b70692c commit 4c9dc31
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/OptionalObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public static function ofNullable(mixed $value): static
return new class ($value) extends OptionalObject { # @phpstan-ignore-line
protected static function getInstanceOf(): string
{
self::logNotice(OptionalObject::class . ' does not check the instance of object.');
/** @var class-string */
return self::ANY_INSTANCE_OF;
}
Expand Down
1 change: 0 additions & 1 deletion src/OptionalResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public static function ofNullable(mixed $value): static
return new class ($value) extends OptionalResource { # @phpstan-ignore-line
protected static function getResourceType(): string
{
self::logNotice(OptionalResource::class . ' does not check the type of resource.');
/** @var non-empty-string */
return self::ANY_RESOURCE_TYPE;
}
Expand Down
7 changes: 3 additions & 4 deletions tests/IdeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ final class IdeTest extends TestCase
{
public function testCheckThisInYourIde(): void
{
/** @var Optional<self> $optional */
$optional = Optional::of($this);
$optional = IdeTestOptional::of($this);

if ($optional->isPresent()) {
$optional->get()->tryIt(); # <--- HERE
Expand All @@ -23,8 +22,8 @@ public function testCheckThisInYourIde(): void

$optional->filter(static fn (): bool => true)->orElseThrow()->tryIt(); # <--- HERE

Optional::of(0)->flatMap(fn (): Optional => Optional::of($this))->orElseThrow()->tryIt(); # <--- HERE @todo fix it
Optional::of(0)->map(fn (): self => $this)->orElseThrow()->tryIt(); # <--- HERE @todo fix it
Optional::of(0)->flatMap(fn (): IdeTestOptional => IdeTestOptional::of($this))->orElseThrow()->tryIt(); # <--- HERE @todo fix it
Optional::of(0)->map(fn (): IdeTest => $this)->orElseThrow()->tryIt(); # <--- HERE @todo fix it

self::markTestSkipped('Try placing the cursor over each `tryIt` call.');
}
Expand Down
16 changes: 16 additions & 0 deletions tests/IdeTestOptional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PetrKnap\Optional;

/**
* @extends OptionalObject<IdeTest>
*/
final class IdeTestOptional extends OptionalObject
{
protected static function getInstanceOf(): string
{
return IdeTest::class;
}
}
19 changes: 18 additions & 1 deletion tests/OptionalResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,24 @@ public function testUsesCorrectType()
{
self::assertInstanceOf(
OptionalResource\OptionalStream::class,
OptionalResource::of(tmpfile()),
OptionalResource::of(fopen('php://memory', 'rw')),
);
}

public function testEqualResourcesAreEqual(): void
{
$r = fopen('php://memory', 'rw');
$a = OptionalResource::of($r);
$b = OptionalResource::of($r);

self::assertTrue($a->equals($b));
}

public function testDifferentResourcesAreNotEqual(): void
{
$a = OptionalResource::of(fopen('php://memory', 'rw'));
$b = OptionalResource::of(fopen('php://memory', 'rw'));

self::assertFalse($a->equals($b));
}
}
4 changes: 2 additions & 2 deletions tests/TypedOptionalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public static function dataCouldBeCreated(): array
// Non-scalars
'array' => [OptionalArray::class, []],
'object' => [OptionalObject::class, new stdClass(), ['object(stdClass)']],
'resource' => [OptionalResource::class, tmpfile(), ['resource(stream)']],
'resource' => [OptionalResource::class, fopen('php://memory', 'rw'), ['resource(stream)']],
// Objects
'object(stdClass)' => [OptionalObject\OptionalStdClass::class, new stdClass(), ['object']],
// Resources
'resource(stream)' => [OptionalResource\OptionalStream::class, tmpfile(), ['resource']],
'resource(stream)' => [OptionalResource\OptionalStream::class, fopen('php://memory', 'rw'), ['resource']],
];
}

Expand Down

0 comments on commit 4c9dc31

Please sign in to comment.