Untitled

 avatar
user_6475215
php
a year ago
4.2 kB
1
Indexable
Never
<?
...
// on the setup of the test i have this code

  public function setUp(): void
  {
    parent::setUp();

    $this->seed();
    $this->app->make(\Spatie\Permission\PermissionRegistrar::class)->forgetCachedPermissions();
    $this->app->make(\Spatie\Permission\PermissionRegistrar::class)->registerPermissions();
    Helpers::getInstance()->GetServerHelper()->ReloadData();
    $this->entityModel = Helpers::getInstance()->GetServerHelper()->GetEntityModel();
    $this->authUser = Helpers::getInstance()->GetServerHelper()->GetAffectedUser();
    $adminRole = Role::where('name', '=', SystemRoles::Admin->name)->first();
    $this->authUser->assignRole($adminRole);
    Storage::fake('local');
  }
  
...

// this the test it self
public function create_server_test() {
    $payload =  Helpers::getInstance()->GetServerHelper()->GetMockServerPayload();
    try {
      $input = new ServerInput(
        $payload['ip'],
        $payload['port'],
        $payload['username'],
        $payload['use_certificate'],
        $payload['certificate_file'],
        $payload['certificate_private_key_file'],
        $payload['certificate_hashing'],
        $payload['bundle_directory'],
        $payload['bundle_prefix'],
        $payload['country'],
        $payload['production_directory'],
        $payload['settings'],
        ['tag1', 'tag2'],
        $payload['allow_new_users']
      );
      $result = Helpers::getInstance()->GetServerHelper()->GetRepo()->CreateServer($this->entityModel->id, $input);
      $this->assertNotNull($result);
      $this->assertDatabaseHas('servers', [
        'server_group_id' => $this->entityModel->id,
        'ip' => $payload['ip'],
        'port' => $payload['port'],
        'username' => $payload['username'],
        'use_certificate' => $payload['use_certificate'],
        'certificate_file' => $payload['certificate_file'],
        'certificate_private_key_file' => $payload['certificate_private_key_file'],
        'certificate_hashing' => $payload['certificate_hashing'],
        'bundle_directory' => $payload['bundle_directory'],
        'bundle_prefix' => $payload['bundle_prefix'],
        'country' => $payload['country'],
        'production_directory' => $payload['production_directory'],
        'settings' => $payload['settings'],
        'allow_new_users' => $payload['allow_new_users']
      ]);
      $this->assertDatabaseHas('tags', [
        'entity_id' => $result->id,
        'entity_type' => Server::TABLE_NAME,
        'tag' => 'tag1'
      ]);
    } catch (EntityNotFoundException|EntityDuplicateRecordException $e) {
      $this->fail($e->getMessage());
    }
  }
...
// this the helper method

public function GetMockServerPayload(){
    $path = fake()->filePath();
    return [
      'ip' => fake()->ipv6(),
      'port' => fake()->numberBetween(1000, 65535),
      'username' => fake()->userName(),
      'use_certificate' => true,
      'certificate_file' => fake()->file(),
      'certificate_private_key_file' => fake()->file($path),
      'certificate_hashing' => fake()->md5(),
      'bundle_directory' => fake()->filePath(),
      'bundle_prefix' => fake()->word(),
      'country' => fake()->country(),
      'production_directory' => fake()->filePath(),
      'settings' => [
        'prop1' => fake()->uuid(),
        'prop2' => fake()->uuid()
      ],
      'allow_new_users' => true,
      'active' => true
    ];
  }
...
?>

i crash on fake->file() or fake->file($path) try both failed

i get this unclear error

InvalidArgumentException: Source and target directories must differ.
/Users/sivan/projects/wolberg-pro/site-generator/vendor/fakerphp/faker/src/Faker/Provider/File.php:587
/Users/sivan/projects/wolberg-pro/site-generator/vendor/fakerphp/faker/src/Faker/Generator.php:696
/Users/sivan/projects/wolberg-pro/site-generator/vendor/fakerphp/faker/src/Faker/Generator.php:961
/Users/sivan/projects/wolberg-pro/site-generator/tests/Unit/Helpers/Admin/ServerHelper.php:157
/Users/sivan/projects/wolberg-pro/site-generator/tests/Unit/Admin/ServerDatabaseTest.php:872
/Users/sivan/projects/wolberg-pro/site-generator/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:174


i also search anywhere and found nogthing on the docs