Skip to content

Commit

Permalink
test: add further tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonTheAdams committed Aug 3, 2023
1 parent a7a3db0 commit 0d74e44
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Framework/FieldsAPI/Concerns/HasPersistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

use Give\Framework\FieldsAPI\ValueObjects\PersistenceScope;

/**
* This provides the ability to set a scope and meta key for a field. The scope is used to determine if and where the
* field should be stored. The meta key is used to store the field in the database.
*
* @unreleased
*/
trait HasPersistence
{
/**
Expand Down
22 changes: 21 additions & 1 deletion tests/Unit/Framework/FieldsAPI/Concerns/HasPersistenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,41 @@ public function testStoreAsDonorMetaMethods()
$this->assertFalse($mock->shouldStoreAsDonorMeta());
}

/**
* @unreleased
*/
public function testSettingTheScopeByString()
{
/** @var HasPersistence $mock */
$mock = $this->getMockForTrait(HasPersistence::class);

$mock->scope('test');
$this->assertEquals('test', $mock->getScopeValue());
$this->assertSame('test', $mock->getScopeValue());
$this->assertTrue($mock->getScope()->is('test'));
}

/**
* @unreleased
*/
public function testSettingTheScopeByInstance()
{
/** @var HasPersistence $mock */
$mock = $this->getMockForTrait(HasPersistence::class);

$mock->scope(new PersistenceScope('test'));
$this->assertEquals('test', $mock->getScopeValue());
$this->assertTrue($mock->getScope()->is('test'));
}

/**
* @unreleased
*/
public function testSettingTheMetaKey()
{
/** @var HasPersistence $mock */
$mock = $this->getMockForTrait(HasPersistence::class);

$mock->metaKey('test');
$this->assertEquals('test', $mock->getMetaKey());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Unit\Framework\FieldsAPI\ValueObjects;

use Give\Framework\FieldsAPI\ValueObjects\PersistenceScope;
use Give\Tests\TestCase;

/**
* @coversDefaultClass \Give\Framework\FieldsAPI\ValueObjects\PersistenceScope
*/
class PersistenceScopeTest extends TestCase
{
/**
* @unreleased
*/
public function testStaticBuilders(): void
{
$donation = PersistenceScope::donation();
$donor = PersistenceScope::donor();

self::assertInstanceOf(PersistenceScope::class, $donation);
self::assertTrue($donation->isDonation());

self::assertInstanceOf(PersistenceScope::class, $donor);
self::assertTrue($donor->isDonor());
}

/**
* @unreleased
*/
public function testToString()
{
$scope = PersistenceScope::donation();
self::assertEquals('donation', (string)$scope);
}

/**
* @unreleased
*/
public function testIsMethods()
{
$donation = PersistenceScope::donation();

self::assertTrue($donation->isDonation());
self::assertFalse($donation->isDonor());
self::assertTrue($donation->is(PersistenceScope::DONATION));
}

/**
* @unreleased
*/
public function testConstructor()
{
$scope = new PersistenceScope('donation');
self::assertTrue($scope->isDonation());
}
}

0 comments on commit 0d74e44

Please sign in to comment.