Skip to content
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
Expand Up @@ -43,7 +43,7 @@ public function isLower(mixed $lower, mixed $higher, array $options): bool
return false;
}

return $higher < $lower;
return $lower < $higher;
}

/**
Expand All @@ -56,6 +56,11 @@ public function isEqual(mixed $value, mixed $nextValue, array $options): bool
return false;
}

return $value == $nextValue;
if ($value instanceof \DateTimeImmutable) {
$value = $value->getTimestamp();
$nextValue = $nextValue->getTimestamp();
}

return $value === $nextValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

/*
* This file is part of the RollerworksSearch package.
*
* (c) Sebastiaan Stok <s.stok@rollerscapes.net>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Extension\Core\ValueComparison;

use PHPUnit\Framework\TestCase;
use Rollerworks\Component\Search\Extension\Core\ValueComparator\BirthdayValueComparator;

/**
* @internal
*/
final class BirthdayValueComparatorTest extends TestCase
{
private BirthdayValueComparator $comparison;

protected function setUp(): void
{
$this->comparison = new BirthdayValueComparator();
}

/**
* @test
*/
public function value_equals(): void
{
self::assertTrue($this->comparison->isEqual(new \DateTimeImmutable('2013-09-21 12:46:00'), new \DateTimeImmutable('2013-09-21 12:46:00'), []));
self::assertTrue($this->comparison->isEqual(1, 1, []));
}

/**
* @test
*/
public function value_not_equals(): void
{
self::assertFalse($this->comparison->isEqual(1, 2, []));
self::assertFalse($this->comparison->isEqual(new \DateTimeImmutable('2013-09-21 12:46:00'), new \DateTimeImmutable('2013-09-22 12:46:00'), []));
self::assertFalse($this->comparison->isEqual(new \DateTimeImmutable('2013-09-21 12:46:00'), 0, []));
}

/**
* @test
*/
public function first_value_is_higher(): void
{
self::assertTrue($this->comparison->isHigher(5, 1, []));
self::assertTrue($this->comparison->isHigher(new \DateTimeImmutable('2013-09-23 12:46:00'), new \DateTimeImmutable('2013-09-21 12:46:00'), []));

// Difference types cannot be compared
self::assertFalse($this->comparison->isHigher(new \DateTimeImmutable('2013-09-23 12:46:00'), 1, []));
self::assertFalse($this->comparison->isHigher(1, new \DateTimeImmutable('2013-09-23 12:46:00'), []));
}

/**
* @test
*/
public function it_returns_true_when_first_value_is_lower(): void
{
self::assertTrue($this->comparison->isLower(2, 5, []));
self::assertTrue($this->comparison->isLower(new \DateTimeImmutable('2013-09-21 12:46:00'), new \DateTimeImmutable('2013-09-23 12:46:00'), []));

// Difference types cannot be compared
self::assertFalse($this->comparison->isLower(new \DateTimeImmutable('2013-09-23 12:46:00'), 1, []));
self::assertFalse($this->comparison->isLower(1, new \DateTimeImmutable('2013-09-23 12:46:00'), []));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

/*
* This file is part of the RollerworksSearch package.
*
* (c) Sebastiaan Stok <s.stok@rollerscapes.net>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Extension\Core\ValueComparison;

use Carbon\CarbonInterval;
use PHPUnit\Framework\TestCase;
use Rollerworks\Component\Search\Extension\Core\ValueComparator\DateTimeIntervalValueComparator;

/**
* @internal
*/
final class DateTimeIntervalValueComparatorTest extends TestCase
{
private DateTimeIntervalValueComparator $comparison;

protected function setUp(): void
{
$this->comparison = new DateTimeIntervalValueComparator();
}

/**
* @test
*/
public function true_when_equal(): void
{
self::assertTrue($this->comparison->isEqual(CarbonInterval::fromString('32m'), CarbonInterval::fromString('32m'), []));
self::assertTrue($this->comparison->isEqual(CarbonInterval::fromString('1w 3d 4h 32m 23s'), CarbonInterval::fromString('1w 3d 4h 32m 23s'), []));
self::assertTrue($this->comparison->isEqual(new \DateTimeImmutable('2013-09-22 12:46:00'), new \DateTimeImmutable('2013-09-22 12:46:00'), []));
}

/**
* @test
*/
public function false_when_not_equal(): void
{
self::assertFalse($this->comparison->isEqual(CarbonInterval::fromString('2w'), CarbonInterval::fromString('1w'), []));
self::assertFalse($this->comparison->isEqual(new \DateTimeImmutable('2013-09-21 12:46:00'), new \DateTimeImmutable('2013-09-22 12:46:00'), []));
self::assertFalse($this->comparison->isEqual(new \DateTimeImmutable('2013-09-21 12:46:00'), new \DateTimeImmutable('2013-09-21 12:40:00'), []));

// Difference types cannot be compared
self::assertFalse($this->comparison->isEqual(CarbonInterval::fromString('2w'), new \DateTimeImmutable('2013-09-21 12:40:00'), []));
}

/**
* @test
*/
public function first_higher(): void
{
self::assertTrue($this->comparison->isHigher(new \DateTimeImmutable('2013-09-23 12:46:00'), new \DateTimeImmutable('2013-09-21 12:46:00'), []));
self::assertTrue($this->comparison->isHigher(CarbonInterval::fromString('35m'), new \DateTimeImmutable('2013-09-21 12:46:00'), []));
self::assertTrue($this->comparison->isHigher(CarbonInterval::fromString('35m'), CarbonInterval::fromString('32m'), []));
}

/**
* @test
*/
public function is_lower(): void
{
self::assertTrue($this->comparison->isLower(new \DateTimeImmutable('2013-09-21 12:46:00'), new \DateTimeImmutable('2013-09-23 12:46:00'), []));
self::assertTrue($this->comparison->isLower(new \DateTimeImmutable('2013-09-21 12:46:00'), CarbonInterval::fromString('30m'), []));
self::assertTrue($this->comparison->isLower(CarbonInterval::fromString('30m'), CarbonInterval::fromString('32m'), []));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Rollerworks\Component\Search\Tests\Extension\Core\ValueComparison;

use Money\Currency;
use Money\Money;
use PHPUnit\Framework\TestCase;
use Rollerworks\Component\Search\Extension\Core\Model\MoneyValue;
Expand Down
Loading