This repository has been archived by the owner on Feb 7, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom Bitrix24 assertion and integration test.
Introduced a new trait `CustomBitrix24Assertions` for verifying Bitrix24 API fields against PHPDoc annotations. Incorporated the new assertion in `ContactTest` and adjusted `composer.json` to include necessary dependencies. Signed-off-by: mesilov <[email protected]>
- Loading branch information
Showing
3 changed files
with
52 additions
and
5 deletions.
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
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,36 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Bitrix24\SDK\Tests\CustomAssertions; | ||
|
||
use Bitrix24\SDK\Services\CRM\Contact\Result\ContactItemResult; | ||
use Typhoon\Reflection\TyphoonReflector; | ||
|
||
trait CustomBitrix24Assertions | ||
{ | ||
/** | ||
* @param array<int, non-empty-string> $fieldCodesFromApi | ||
* @param class-string $resultItemClassName | ||
* @return void | ||
*/ | ||
protected function assertBitrix24AllResultItemFieldsAnnotated(array $fieldCodesFromApi, string $resultItemClassName): void | ||
{ | ||
sort($fieldCodesFromApi); | ||
|
||
// parse keys from phpdoc annotation | ||
$props = TyphoonReflector::build()->reflectClass($resultItemClassName)->properties(); | ||
$propsFromAnnotations = []; | ||
foreach ($props as $meta) { | ||
if ($meta->isAnnotated() && !$meta->isNative()) { | ||
$propsFromAnnotations[] = $meta->id->name; | ||
} | ||
} | ||
sort($propsFromAnnotations); | ||
|
||
$this->assertEquals($fieldCodesFromApi, $propsFromAnnotations, | ||
sprintf('in phpdocs annotations for class %s we not found fields from actual api response: %s', | ||
$resultItemClassName, | ||
implode(', ', array_values(array_diff($fieldCodesFromApi, $propsFromAnnotations))) | ||
)); | ||
} | ||
} |
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