File manager - Edit - /var/www/html/homologBancodetalentos/tests/Unit/TalentBank/LegacyMigrationNormalizersTest.php
Back
<?php namespace Tests\Unit\TalentBank; use App\Support\TalentBank\LegacyMigrationImporter; use PHPUnit\Framework\TestCase; use ReflectionClass; use ReflectionMethod; /** * Testa os helpers de normalização privados do LegacyMigrationImporter via reflexão. * Todos os métodos testados são puros (sem I/O de banco), portanto unit puro. */ class LegacyMigrationNormalizersTest extends TestCase { private LegacyMigrationImporter $importer; private ReflectionClass $ref; protected function setUp(): void { parent::setUp(); $this->importer = new LegacyMigrationImporter( legacyConnection: 'sqlite', targetConnection: 'sqlite', tables: [ 'candidates' => 'candidates', 'companies' => 'companies', 'jobs' => 'jobs', 'job_applications' => 'job_applications', ], ); $this->ref = new ReflectionClass($this->importer); } /** Chama um método privado do importer com os args fornecidos. */ private function call(string $method, mixed ...$args): mixed { $m = $this->ref->getMethod($method); $m->setAccessible(true); return $m->invoke($this->importer, ...$args); } // ───────────────────────────────────────────────────────────────────────── // nullableInt // ───────────────────────────────────────────────────────────────────────── /** @test */ public function nullable_int_retorna_null_para_null(): void { $this->assertNull($this->call('nullableInt', null)); } /** @test */ public function nullable_int_retorna_null_para_string_vazia(): void { $this->assertNull($this->call('nullableInt', '')); } /** @test */ public function nullable_int_retorna_null_para_zero(): void { $this->assertNull($this->call('nullableInt', 0)); } /** @test */ public function nullable_int_retorna_int_positivo(): void { $this->assertSame(42, $this->call('nullableInt', '42')); } /** @test */ public function nullable_int_converte_string_numerica(): void { $this->assertSame(100, $this->call('nullableInt', '100')); } // ───────────────────────────────────────────────────────────────────────── // nullableString // ───────────────────────────────────────────────────────────────────────── /** @test */ public function nullable_string_retorna_null_para_null(): void { $this->assertNull($this->call('nullableString', null)); } /** @test */ public function nullable_string_retorna_null_para_string_vazia(): void { $this->assertNull($this->call('nullableString', '')); } /** @test */ public function nullable_string_retorna_null_para_somente_espacos(): void { $this->assertNull($this->call('nullableString', ' ')); } /** @test */ public function nullable_string_retorna_null_para_literal_null(): void { $this->assertNull($this->call('nullableString', 'NULL')); } /** @test */ public function nullable_string_faz_trim(): void { $this->assertSame('teste', $this->call('nullableString', ' teste ')); } // ───────────────────────────────────────────────────────────────────────── // normalizeBool // ───────────────────────────────────────────────────────────────────────── /** @test */ public function normalize_bool_aceita_true_nativo(): void { $this->assertTrue($this->call('normalizeBool', true)); } /** @test */ public function normalize_bool_aceita_false_nativo(): void { $this->assertFalse($this->call('normalizeBool', false)); } /** @test */ public function normalize_bool_aceita_int_1(): void { $this->assertTrue($this->call('normalizeBool', 1)); } /** @test */ public function normalize_bool_aceita_int_0(): void { $this->assertFalse($this->call('normalizeBool', 0)); } /** @test */ public function normalize_bool_aceita_string_1(): void { $this->assertTrue($this->call('normalizeBool', '1')); } /** @test */ public function normalize_bool_aceita_string_aberta(): void { $this->assertTrue($this->call('normalizeBool', 'a')); } /** @test */ public function normalize_bool_aceita_string_sim(): void { $this->assertTrue($this->call('normalizeBool', 'sim')); } /** @test */ public function normalize_bool_retorna_false_para_valor_desconhecido(): void { $this->assertFalse($this->call('normalizeBool', 'talvez')); } // ───────────────────────────────────────────────────────────────────────── // nullablePhone // ───────────────────────────────────────────────────────────────────────── /** @test */ public function nullable_phone_retorna_null_para_zero(): void { $this->assertNull($this->call('nullablePhone', 0)); } /** @test */ public function nullable_phone_retorna_null_para_null(): void { $this->assertNull($this->call('nullablePhone', null)); } /** @test */ public function nullable_phone_remove_nao_digitos(): void { $this->assertSame('24999123456', $this->call('nullablePhone', '(24) 99912-3456')); } /** @test */ public function nullable_phone_aceita_bigint_legado(): void { // O legado armazenava telefones como bigint $this->assertSame('24981175347', $this->call('nullablePhone', 24981175347)); } // ───────────────────────────────────────────────────────────────────────── // cappedPayment // ───────────────────────────────────────────────────────────────────────── /** @test */ public function capped_payment_retorna_null_para_null(): void { $this->assertNull($this->call('cappedPayment', null)); } /** @test */ public function capped_payment_retorna_null_para_string_vazia(): void { $this->assertNull($this->call('cappedPayment', '')); } /** @test */ public function capped_payment_retorna_null_para_zero(): void { $this->assertNull($this->call('cappedPayment', 0)); } /** @test */ public function capped_payment_retorna_valor_positivo(): void { $this->assertSame(1500.0, $this->call('cappedPayment', '1500')); } /** @test */ public function capped_payment_limita_ao_maximo_do_decimal_12_2(): void { $max = 9999999999.99; $this->assertSame($max, $this->call('cappedPayment', 99999999999.99)); } /** @test */ public function capped_payment_aceita_valor_proximo_do_limite(): void { $this->assertSame(9999999999.99, $this->call('cappedPayment', 9999999999.99)); } // ───────────────────────────────────────────────────────────────────────── // normalizeLegacyCpf // ───────────────────────────────────────────────────────────────────────── /** @test */ public function normalize_legacy_cpf_padeia_bigint_sem_zero(): void { // CPF armazenado como bigint perde o zero inicial $this->assertSame('01234567890', $this->call('normalizeLegacyCpf', 1234567890)); } /** @test */ public function normalize_legacy_cpf_retorna_null_para_zero(): void { $this->assertNull($this->call('normalizeLegacyCpf', 0)); } /** @test */ public function normalize_legacy_cpf_retorna_null_para_string_vazia(): void { $this->assertNull($this->call('normalizeLegacyCpf', '')); } /** @test */ public function normalize_legacy_cpf_aceita_string_com_11_digitos(): void { $this->assertSame('16140014727', $this->call('normalizeLegacyCpf', '16140014727')); } /** @test */ public function normalize_legacy_cpf_retorna_null_para_mais_de_11_digitos(): void { $this->assertNull($this->call('normalizeLegacyCpf', '1234567890123')); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings