Skip to content

Commit

Permalink
refactor via failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gwleuverink committed Aug 26, 2024
1 parent 2abaf28 commit 44a254c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
8 changes: 4 additions & 4 deletions tests/Integration/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public function getGroupA()
{
$this->result = $this->group('a');
$this->result = $this->group('a')->toArray();
}
})
->call('getGroupA')
Expand All @@ -46,7 +46,7 @@ public function getGroupA()

public function getGroupB()
{
$this->result = $this->group('b');
$this->result = $this->group('b')->toArray();
}
})
->call('getGroupB')
Expand All @@ -56,7 +56,7 @@ public function getGroupB()
]);
});

it('can retreive multiple groups at once', function () {
it('can retrieve multiple groups at once', function () {
Livewire::test(new class extends TestComponent
{
#[Group('a')]
Expand All @@ -69,7 +69,7 @@ public function getGroupB()

public function getGroupB()
{
$this->result = $this->group(['a', 'b']);
$this->result = $this->group(['a', 'b'])->toArray();
}
})
->call('getGroupB')
Expand Down
73 changes: 42 additions & 31 deletions tests/Unit/MacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,54 @@
};

expect(group($component, 'a'))
->toBe([
'foo' => 1,
]);
->toHaveKey('foo')
->toContain(1);
});

it('returns array keys when keys() method was chained', function () {
it('returns array keys when `keys` method was chained', function () {
$component = new class extends TestComponent
{
#[Group('a')]
public $foo = 1;
};

expect(
group($component, 'a')->keys()
)
->toBe([
'foo',
]);
expect(group($component, 'a'))
->keys()
->toBeArray()
->toContain('foo');
});

it('returns array values when values() method was chained', function () {
it('returns array values when `values` method was chained', function () {
$component = new class extends TestComponent
{
#[Group('a')]
public $foo = 1;
};

expect(
group($component, 'a')->values()
)
->toBe([
1,
]);
expect(group($component, 'a'))
->values()
->toBeArray()
->toContain(1);
});

it('has no unexpected side effects if both keys() and values() are called in the same chain', function () {
it('can iterate over properties in a group when the `each` method was chained', function () {
$component = new class extends TestComponent
{
#[Group('a')]
public $foo = 1;

#[Group('a')]
public $bar = 2;
};

expect(
group($component, 'a')->keys()->values()
)
->toBe([
1,
]);
$iterations = 0;

group($component, 'a')->each(fn () => $iterations++);

expect($iterations)->toBe(2);
});

it('can iterate over properties in a group when the each() method was chained', function () {
it('can chain on the `each` method', function () {
$component = new class extends TestComponent
{
#[Group('a')]
Expand All @@ -73,14 +70,28 @@
public $bar = 2;
};

$iterations = 0;
expect(group($component, 'a'))
->each(function () {
// Don't have to do anything here
})
->values()
->toBeArray()
->toContain(1, 2);
});

group($component, 'a')->each(fn () => $iterations++);
it('can transform PropertyCollection to a array', function () {
$component = new class extends TestComponent
{
#[Group('a')]
public $foo = 1;
};

expect($iterations)->toBe(2);
$result = group($component, 'a')->toArray();

expect($result)->toBeArray();
});

// Should be Integration tests? Component not mounted on unit level. Can't reset properties this way
it('resets all properties in a group when the reset() method was chained')->todo(); // add two groups for unhappy path
it('returns & resets all properties in a group when the pull() method was chained')->todo(); // add two groups for unhappy path
it('validates all properties in a group when the validate() method was chained')->todo(); // add two groups for unhappy path
it('resets all properties in a group when the `reset` method was chained')->todo(); // add two groups for unhappy path
it('returns & resets all properties in a group when the `pull` method was chained')->todo(); // add two groups for unhappy path
it('validates all properties in a group when the `validate` method was chained')->todo(); // add two groups for unhappy path

0 comments on commit 44a254c

Please sign in to comment.