|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace TeamWorkPm\Tests; |
| 4 | + |
| 5 | +final class InvoiceTest extends TestCase |
| 6 | +{ |
| 7 | + /** |
| 8 | + * @dataProvider provider |
| 9 | + */ |
| 10 | + public function testCreate(array $data): void |
| 11 | + { |
| 12 | + $this->assertEquals(TPM_TEST_ID, $this->factory('invoice', [ |
| 13 | + 'POST /projects/' . TPM_PROJECT_ID_1 . '/invoices' => fn($data) => $this->assertMatchesJsonSnapshot($data) |
| 14 | + ])->create($data)); |
| 15 | + } |
| 16 | + |
| 17 | + public function testAll(): void |
| 18 | + { |
| 19 | + $this->assertGreaterThan(0, count($this->factory('invoice', [ |
| 20 | + 'GET /invoices' => true |
| 21 | + ])->all())); |
| 22 | + } |
| 23 | + |
| 24 | + public function testGetByProject(): void |
| 25 | + { |
| 26 | + $this->assertGreaterThan(0, count($this->factory('invoice', [ |
| 27 | + 'GET /projects/' . TPM_PROJECT_ID_1 . '/invoices' => true |
| 28 | + ])->getByProject(TPM_PROJECT_ID_1))); |
| 29 | + } |
| 30 | + |
| 31 | + public function testGet(): void |
| 32 | + { |
| 33 | + $this->assertEquals('USD', $this->factory('invoice', [ |
| 34 | + 'GET /invoices/' . TPM_INVOICE_ID => true |
| 35 | + ])->get(TPM_INVOICE_ID)->currencyCode); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * @dataProvider provider |
| 40 | + */ |
| 41 | + public function testUpdate(array $data): void |
| 42 | + { |
| 43 | + $data['id'] = TPM_INVOICE_ID; |
| 44 | + $data['description'] = 'Updated Invoice Description'; |
| 45 | + $this->assertTrue($this->factory('invoice', [ |
| 46 | + 'PUT /invoices/' . TPM_INVOICE_ID => true |
| 47 | + ])->update($data)); |
| 48 | + } |
| 49 | + |
| 50 | + public function testComplete(): void |
| 51 | + { |
| 52 | + $this->assertTrue($this->factory('invoice', [ |
| 53 | + 'PUT /invoices/' . TPM_INVOICE_ID . '/complete' => true |
| 54 | + ])->complete(TPM_INVOICE_ID)); |
| 55 | + } |
| 56 | + |
| 57 | + public function testUnComplete(): void |
| 58 | + { |
| 59 | + $this->assertTrue($this->factory('invoice', [ |
| 60 | + 'PUT /invoices/' . TPM_INVOICE_ID . '/uncomplete' => true |
| 61 | + ])->unComplete(TPM_INVOICE_ID)); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @todo This test fail on real api |
| 66 | + * |
| 67 | + * @return void |
| 68 | + */ |
| 69 | + public function testAddTime(): void |
| 70 | + { |
| 71 | + $this->assertTrue($this->factory('invoice', [ |
| 72 | + 'PUT /invoices/' . TPM_INVOICE_ID . '/lineitems' => true |
| 73 | + ])->addTime(TPM_INVOICE_ID, '10 hours')); |
| 74 | + } |
| 75 | + |
| 76 | + public function testDelete(): void |
| 77 | + { |
| 78 | + $this->assertTrue($this->factory('invoice', [ |
| 79 | + 'DELETE /invoices/' . TPM_INVOICE_ID => true |
| 80 | + ])->delete(TPM_INVOICE_ID)); |
| 81 | + } |
| 82 | + |
| 83 | + public function provider() |
| 84 | + { |
| 85 | + return [ |
| 86 | + [ |
| 87 | + [ |
| 88 | + 'description' => 'Bla, Bla, Bla', |
| 89 | + 'number' => 100, |
| 90 | + 'project_id' => TPM_PROJECT_ID_1, |
| 91 | + 'display_date' => '20250101' |
| 92 | + ], |
| 93 | + ], |
| 94 | + ]; |
| 95 | + } |
| 96 | +} |
0 commit comments