Skip to content

Commit

Permalink
feat: add field repo fake
Browse files Browse the repository at this point in the history
  • Loading branch information
Katalam committed Jul 4, 2024
1 parent 82a0a35 commit 3d46798
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
## main

## v0.8.1
- Added a field repository fake

## v.0.8.0
- Added the parameter helper to all repositories

Expand Down
9 changes: 9 additions & 0 deletions src/Facades/FieldRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Katalam\OnOfficeAdapter\Facades;

use Illuminate\Support\Facades\Facade;
use Katalam\OnOfficeAdapter\Facades\Testing\AddressRepositoryFake;
use Katalam\OnOfficeAdapter\Facades\Testing\FieldRepositoryFake;
use Katalam\OnOfficeAdapter\Query\FieldBuilder;

/**
Expand All @@ -14,6 +16,13 @@
*/
class FieldRepository extends Facade
{
public static function fake(array ...$fakeResponses): FieldRepositoryFake
{
static::swap($fake = new FieldRepositoryFake(...$fakeResponses));

return $fake;
}

protected static function getFacadeAccessor(): string
{
return \Katalam\OnOfficeAdapter\Repositories\FieldRepository::class;
Expand Down
20 changes: 20 additions & 0 deletions src/Facades/Testing/FieldRepositoryFake.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Katalam\OnOfficeAdapter\Facades\Testing;

use Katalam\OnOfficeAdapter\Query\Testing\FieldBuilderFake;

class FieldRepositoryFake
{
use FakeResponses;

/**
* Returns a new fake estate builder instance.
*/
public function query(): FieldBuilderFake
{
return new FieldBuilderFake($this->fakeResponses);
}
}
2 changes: 1 addition & 1 deletion src/Facades/Testing/RecordFactories/BaseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

abstract class BaseFactory
{
public int $id = 0;
public int|string $id = 0;

public string $type = '';

Expand Down
10 changes: 10 additions & 0 deletions src/Facades/Testing/RecordFactories/FieldFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Katalam\OnOfficeAdapter\Facades\Testing\RecordFactories;

class FieldFactory extends BaseFactory
{
public int|string $id = 'address';
}
28 changes: 28 additions & 0 deletions src/Query/Testing/FieldBuilderFake.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Katalam\OnOfficeAdapter\Query\Testing;

use Exception;
use Illuminate\Support\Arr;
use Katalam\OnOfficeAdapter\Query\Concerns\RecordIds;
use Throwable;

class FieldBuilderFake extends BaseFake
{
use RecordIds;

public function withModules(array|string $modules): static
{
return $this;
}

/**
* @throws Throwable
*/
public function create(array $data): array
{
return $this->get()->first();
}
}

0 comments on commit 3d46798

Please sign in to comment.