-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,000 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace TeamWorkPm; | ||
|
||
use TeamWorkPm\Rest\Resource; | ||
use TeamWorkPm\Rest\Resource\GetAllTrait; | ||
|
||
class Currency extends Resource | ||
{ | ||
use GetAllTrait; | ||
|
||
protected ?string $parent = 'currency-codes'; | ||
|
||
protected ?string $action = 'currencycodes'; | ||
|
||
protected string|array $fields = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace TeamWorkPm; | ||
|
||
use TeamWorkPm\Rest\Resource\Model; | ||
use TeamWorkPm\Rest\Resource\Project\ActionTrait as ProjectTrait; | ||
use TeamWorkPm\Rest\Resource\CompleteTrait; | ||
|
||
/** | ||
* @see https://apidocs.teamwork.com/docs/teamwork/v1/invoices/get-invoices-json | ||
*/ | ||
class Invoice extends Model | ||
{ | ||
use ProjectTrait, CompleteTrait; | ||
|
||
protected ?string $parent = 'invoice'; | ||
|
||
protected ?string $action = 'invoices'; | ||
|
||
protected string|array $fields = 'invoices'; | ||
|
||
public function addTime(int $id, string $time): bool | ||
{ | ||
return $this->notUseFields() | ||
->put("$this->action/$id/lineitems", [ | ||
'lineitems' => [ | ||
'add' => [ | ||
'timelogs' => "$time" | ||
] | ||
] | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"description": { | ||
"type": "string" | ||
}, | ||
"fixed_cost": { | ||
"type": "string", | ||
"transform": "dash" | ||
}, | ||
"number": { | ||
"type": "string", | ||
"required": true | ||
}, | ||
"po_number": { | ||
"type": "string", | ||
"transform": "dash" | ||
}, | ||
"display_date": { | ||
"type": "string", | ||
"transform": "dash", | ||
"required": true | ||
}, | ||
"currency_code": { | ||
"type": "string", | ||
"transform": "dash" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace TeamWorkPm\Tests; | ||
|
||
final class CurrencyTest extends TestCase | ||
{ | ||
public function testAll(): void | ||
{ | ||
$this->assertGreaterThan(0, count($this->factory('currency', [ | ||
'GET /currencycodes' => true | ||
])->all())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace TeamWorkPm\Tests; | ||
|
||
final class InvoiceTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provider | ||
*/ | ||
public function testCreate(array $data): void | ||
{ | ||
$this->assertEquals(TPM_TEST_ID, $this->factory('invoice', [ | ||
'POST /projects/' . TPM_PROJECT_ID_1 . '/invoices' => fn($data) => $this->assertMatchesJsonSnapshot($data) | ||
])->create($data)); | ||
} | ||
|
||
public function testAll(): void | ||
{ | ||
$this->assertGreaterThan(0, count($this->factory('invoice', [ | ||
'GET /invoices' => true | ||
])->all())); | ||
} | ||
|
||
public function testGetByProject(): void | ||
{ | ||
$this->assertGreaterThan(0, count($this->factory('invoice', [ | ||
'GET /projects/' . TPM_PROJECT_ID_1 . '/invoices' => true | ||
])->getByProject(TPM_PROJECT_ID_1))); | ||
} | ||
|
||
public function testGet(): void | ||
{ | ||
$this->assertEquals('USD', $this->factory('invoice', [ | ||
'GET /invoices/' . TPM_INVOICE_ID => true | ||
])->get(TPM_INVOICE_ID)->currencyCode); | ||
} | ||
|
||
/** | ||
* @dataProvider provider | ||
*/ | ||
public function testUpdate(array $data): void | ||
{ | ||
$data['id'] = TPM_INVOICE_ID; | ||
$data['description'] = 'Updated Invoice Description'; | ||
$this->assertTrue($this->factory('invoice', [ | ||
'PUT /invoices/' . TPM_INVOICE_ID => true | ||
])->update($data)); | ||
} | ||
|
||
public function testComplete(): void | ||
{ | ||
$this->assertTrue($this->factory('invoice', [ | ||
'PUT /invoices/' . TPM_INVOICE_ID . '/complete' => true | ||
])->complete(TPM_INVOICE_ID)); | ||
} | ||
|
||
public function testUnComplete(): void | ||
{ | ||
$this->assertTrue($this->factory('invoice', [ | ||
'PUT /invoices/' . TPM_INVOICE_ID . '/uncomplete' => true | ||
])->unComplete(TPM_INVOICE_ID)); | ||
} | ||
|
||
/** | ||
* @todo This test fail on real api | ||
* | ||
* @return void | ||
*/ | ||
public function testAddTime(): void | ||
{ | ||
$this->assertTrue($this->factory('invoice', [ | ||
'PUT /invoices/' . TPM_INVOICE_ID . '/lineitems' => true | ||
])->addTime(TPM_INVOICE_ID, '10 hours')); | ||
} | ||
|
||
public function testDelete(): void | ||
{ | ||
$this->assertTrue($this->factory('invoice', [ | ||
'DELETE /invoices/' . TPM_INVOICE_ID => true | ||
])->delete(TPM_INVOICE_ID)); | ||
} | ||
|
||
public function provider() | ||
{ | ||
return [ | ||
[ | ||
[ | ||
'description' => 'Bla, Bla, Bla', | ||
'number' => 100, | ||
'project_id' => TPM_PROJECT_ID_1, | ||
'display_date' => '20250101' | ||
], | ||
], | ||
]; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/__snapshots__/InvoiceTest__testCreate with data set 0__1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"invoice": { | ||
"description": "Bla, Bla, Bla", | ||
"number": "100", | ||
"display-date": "20250101" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.