Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,39 @@ on:
name: PHPStan checks

jobs:
phpstan:
name: PHPStan
static-analysis:
name: "PHPStan"
runs-on: "ubuntu-latest"

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version:
- "7.4"
- "8.0"
dependencies:
- "lowest"
- "highest"

steps:
- name: "Checkout"
uses: actions/checkout@v2
uses: "actions/checkout@v2"

- name: PHPStan
uses: docker://oskarstark/phpstan-ga
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
args: analyse
coverage: "none"
php-version: "${{ matrix.php-version }}"
extensions: mbstring
tools: composer:v2

- name: "Install lowest dependencies"
if: ${{ matrix.dependencies == 'lowest' }}
run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest"

- name: "Install highest dependencies"
if: ${{ matrix.dependencies == 'highest' }}
run: "composer update --no-interaction --no-progress --no-suggest"

- name: "PHPStan"
run: "composer phpstan-analyse"
7 changes: 2 additions & 5 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,5 @@ jobs:
run: |
composer update ${{ env.COMPOSER_FLAGS }}

- name: "Run tests"
run: "composer exec phpunit -- --verbose"

- name: Run test suite
run: composer run-script unit-tests
- name: "run unit tests"
run: "composer phpunit-run-unit-tests"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ composer.lock
.phpunit.result.cache
tools/.env.local
tools/logs
examples/logs
examples/logs
.env.local
24 changes: 19 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
# bitrix24-php-sdk change log

## 2.0-alpha.4(25.11.2021)
## 2.0-alpha.5 – 26.11.2021

### Added

* add method `countByFilter` for all related services, see
issue [Добавить для всех сущностей метод подсчёта количества элементов по фильтру #228](https://github.com/mesilov/bitrix24-php-sdk/issues/228)

### Removed

* remove all `0.*` and `1.*` code from `2.*` branch

## 2.0-alpha.4 – 25.11.2021

### Changed

* switch `symfony/http-client` to `5.3` version requirement.
* switch `symfony/http-client-contracts` to `^2.4` version requirement.
* switch `symfony/event-dispatcher` to `5.3.*` version requirement.
* switch `ramsey/uuid` to `^4.0` version requirement.

### Fixed

* issue [Несовместимость с Laravel 8 #224](https://github.com/mesilov/bitrix24-php-sdk/issues/224)

## 2.0-alpha.3(14.11.2021)
## 2.0-alpha.314.11.2021

* add php8 version support
* change in scope «CRM» Product service and integration tests
Expand All @@ -22,7 +35,7 @@
* bump phpunit version
* bump phpstan version

## 2.0-alpha.2 (31.01.2021)
## 2.0-alpha.2 31.01.2021

* remove Travis CI and migrate to Github Actions
* add unit-tests in independent github action
Expand All @@ -37,7 +50,7 @@
* add in scope «IM» IM service and integration test
* add in default scope «Main» default service

## 2.0-alpha.1 (11.07.2020)
## 2.0-alpha.1 11.07.2020

* remove all v1 code
* migrate to Symfony HttpClient
Expand All @@ -46,6 +59,7 @@
* add Events support

## 0.1.0 (14.11.2021)

branch version 1.x – bugfix and security releases only

## 0.7.0 (11.07.2020)
Expand Down
130 changes: 93 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,62 @@ bitrix24-php-sdk [![Build Status](https://travis-ci.org/mesilov/bitrix24-php-sdk
[![License](https://poser.pugx.org/mesilov/bitrix24-php-sdk/license.svg)](https://packagist.org/packages/mesilov/bitrix24-php-sdk) [![Total Downloads](https://poser.pugx.org/mesilov/bitrix24-php-sdk/downloads.svg)](https://packagist.org/packages/mesilov/bitrix24-php-sdk)

A powerful PHP library for the Bitrix24 REST API
### BITRIX24-PHP-SDK Documentation

[Bitrix24 API documentation - Russian](http://dev.1c-bitrix.ru/rest_help/)<br />
[Bitrix24 API documentation - English](https://training.bitrix24.com/rest_help/)<br />
[Register new Bitrix24 account](https://www.bitrix24.ru/create.php?p=255670)<br />
- [Russian](/docs/RU/documentation.md)
- [English](/docs/EN/documentation.md)

### SDK 2.0 core features
### BITRIX24-PHP-SDK ✨FEATURES✨

Bitrix24 auth features
Support both auth modes:

- ~~work with auth tokens~~
- ~~work with incoming webhooks~~
- [x] work with auth tokens for Bitrix24 applications in marketplace
- [x] work with incoming webhooks for simple integration projects for current portal

add low-level tools to devs:
Low-level tools to devs:

- ~~2.1 events (token expired, domain url changed)~~
- 2.2 rate-limiter - wait for symfony/symfony#37471
- 2.3 RetryHttpClient - symfony/symfony#38182
- Domain core events:
- [x] Access Token expired
- [ ] Bitrix24 portal domain url changed
- [ ] Rate-limit strategy
- [ ] Retry strategy for safe methods

API - level features

- ~~3.1 auto renew access tokens~~
- 3.2 batch queries (work in progress)
- ~~3.2.1 read~~
- ~~3.2.2 write~~
- 3.2.3 read + write
- 3.2.4 read without count flag
- 3.3 list queries with «start=-1» support
- 3.4 offline queues
- 3.5 add change domain URL support

Core DTO

- ~~Response~~
- ~~Scope~~
- ~~Time~~
- ~~OAuthToken~~
- ~~ApplicationProfile~~
- ~~Pagination~~

### SDK Documentation

- [Russian](/docs/RU/documentation.md)
- [English](/docs/EN/documentation.md)
- [x] Auto renew access tokens
- [ ] List queries with «start=-1» support
- [ ] offline queues

Performance improvements 🚀

- Batch queries implemented with [PHP Generators](https://www.php.net/manual/en/language.generators.overview.php) – constant low memory and
low CPI usage
- [x] batch read data from bitrix24
- [x] batch write data to bitrix24
- [ ] write and read in one batch package
- [ ] composite batch queries to many entities (work in progress)
- [ ] read without count flag

### Development principles

- Good developer experience
- auto-completion of methods at the IDE
- typed method call signatures
- typed results of method calls
- helpers for typical operations
- Good documentation
- documentation on the operation of a specific method containing a link to the official documentation
- documentation for working with the SDK
- Performance first:
- minimal impact on client code
- ability to work with large amounts of data with constant memory consumption
- efficient operation of the API using butch requests
- Modern technology stack
- based on [Symfony HttpClient](https://symfony.com/doc/current/http_client.html)
- actual PHP versions language features
- Reliable:
- test coverage: unit, integration, contract
- typical examples typical for different modes of operation and they are optimized for memory \ performance

### Architecture

Expand Down Expand Up @@ -94,11 +107,46 @@ Core DTO
Add `"mesilov/bitrix24-php-sdk": "2.x"` to `composer.json` of your application. Or clone repo to your project.

### Tests
Tests locate in folder `tests` and we have two test types

#### Unit tests
**Fast**, in-memory tests without a network I\O
For run unit tests you must call in command line

```shell
composer phpunit-run-unit-test
```

#### Integration tests
**Slow** tests with full lifecycle with your **test** Bitrix24 portal via webhook.

❗️Do not run integration tests with production portals ❗️

For run integration test you must:
1. Create [new Bitrix24 portal](https://www.bitrix24.ru/create.php?p=255670) for development tests
2. Go to left menu, click «Sitemap»
3. Find menu item «Developer resources»
4. Click on menu item «Other»
5. Click on menu item «Inbound webhook»
6. Assign all permisions with webhook and click «save» button
7. Create file `/tests/.env.local` with same settings, see comments in `/tests/.env` file.
```yaml
APP_ENV=dev
BITRIX24_WEBHOOK=https:// your portal webhook url
INTEGRATION_TEST_LOG_LEVEL=500
```
8. call in command line

```shell
composer composer phpunit-run-integration-tests
```

SDK test locate in folder `tests` and we have two test types
#### PHP Static Analysis Tool – phpstan
Call in command line
```shell
composer phpstan-analyse
```

- Unit: **fast**, in-memory tests without a network I\O
- Integration: **slow** tests with full lifecycle with test Bitrix24 portal via webhook

### Submitting bugs and feature requests

Expand All @@ -119,6 +167,14 @@ email: <mesilov.maxim@gmail.com>

### Sponsors

### Documentation

[Bitrix24 API documentation - Russian](http://dev.1c-bitrix.ru/rest_help/)

[Bitrix24 API documentation - English](https://training.bitrix24.com/rest_help/)

[Register new Bitrix24 account](https://www.bitrix24.ru/create.php?p=255670)

## Русский

### Принципы по которым ведётся разработка
Expand Down
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
},
"require-dev": {
"monolog/monolog": "2.1.*",
"symfony/console": "5.2.*",
"symfony/dotenv": "5.2.*",
"symfony/debug-bundle": "5.2.*",
"symfony/console": "5.3.*",
"symfony/dotenv": "5.3.*",
"symfony/debug-bundle": "5.3.*",
"phpstan/phpstan": "1.1.*",
"phpunit/phpunit": "9.5.*",
"roave/security-advisories": "dev-master"
Expand All @@ -48,8 +48,11 @@
}
},
"scripts": {
"unit-tests": [
"phpunit --colors=always --verbose"
"phpunit-run-unit-tests": [
"phpunit --testsuite unit_tests"
],
"phpunit-run-integration-tests": [
"phpunit --testsuite integration_tests"
],
"phpstan-analyse": [
"vendor/bin/phpstan analyse"
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parameters:
level: 1
level: 5
paths:
- src/
- tests/
# - tests/
bootstrapFiles:
- tests/bootstrap.php
7 changes: 5 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
bootstrap="tests/bootstrap.php"
failOnRisky="true"
failOnWarning="true">
<coverage>
Expand All @@ -15,8 +15,11 @@
<ini name="error_reporting" value="-1"/>
</php>
<testsuites>
<testsuite name="Bitrix24 PHP SDK unit tests suite">
<testsuite name="unit_tests">
<directory>./tests/Unit</directory>
</testsuite>
<testsuite name="integration_tests">
<directory>./tests/Integration</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 2 additions & 2 deletions src/Core/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public function getTraversable(bool $isHaltOnError): Generator
}

$nextItem = null;
if ($resultNextItems !== null && array_key_exists($singleQueryKey, $resultNextItems) && count($resultNextItems) > 0) {
if ($resultNextItems !== null && array_key_exists($singleQueryKey, $resultNextItems)) {
$nextItem = $resultNextItems[$singleQueryKey];
}

Expand Down Expand Up @@ -544,7 +544,7 @@ private function convertToApiCommands(): array
$apiCommands = [];
foreach ($this->commands as $itemCommand) {
/**
* @var $itemCommand Command
* @var Command $itemCommand
*/
$apiCommands[$itemCommand->getName() ?? $itemCommand->getUuid()->toString()] = sprintf(
'%s?%s',
Expand Down
Loading