diff --git a/.github/actions/test_tests-phpunit.sh b/.github/actions/test_tests-phpunit.sh new file mode 100755 index 00000000000..f966bf35088 --- /dev/null +++ b/.github/actions/test_tests-phpunit.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -e -u -x -o pipefail + +PHPUNIT_ADDITIONNAL_OPTIONS="" +if [[ "$CODE_COVERAGE" = true ]]; then + export COVERAGE_DIR="coverage-functional" + PHPUNIT_ADDITIONNAL_OPTIONS="--coverage-filter src --coverage-clover phpunit/$COVERAGE_DIR/clover.xml" + +else + PHPUNIT_ADDITIONNAL_OPTIONS="--no-coverage"; +fi + +#temporary hack to prevent dual configuration +ln -s ../tests/config/ phpunit/ + +vendor/bin/phpunit $PHPUNIT_ADDITIONNAL_OPTIONS + +unset COVERAGE_DIR diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c7596f64ef6..81570443903 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -175,6 +175,10 @@ jobs: run: | .github/actions/init_initialize-9.5-db.sh docker compose exec -T app .github/actions/test_update-from-9.5.sh + - name: "PHPUnit tests" + if: env.skip != 'true' + run: | + docker compose exec -T app .github/actions/test_tests-phpunit.sh - name: "Functional tests" if: "${{ env.skip != 'true' && (success() || failure()) }}" run: | diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 06890a2e061..40a10961bfd 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -61,6 +61,9 @@ jobs: - name: "Install database" run: | docker compose exec -T app .github/actions/test_install.sh + - name: "PHPUnit tests" + run: | + docker compose exec -T app .github/actions/test_tests-phpunit.sh - name: "Functional tests" run: | docker compose exec -T app .github/actions/test_tests-functional.sh @@ -77,5 +80,5 @@ jobs: env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: - files: ./tests/coverage-functional/clover.xml,./tests/coverage-ldap/clover.xml,./tests/coverage-imap/clover.xml + files: ./phpunit/coverage-functional/clover.xml,./tests/coverage-functional/clover.xml,./tests/coverage-ldap/clover.xml,./tests/coverage-imap/clover.xml override_branch: ${{ inputs.branch }} diff --git a/.gitignore b/.gitignore index 5860ca6f751..d8f19b22219 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,6 @@ phpunit.xml /inc/downstream.php /docker-compose.override.yaml /.devcontainer/docker-compose.override.yaml +/.phpunit.result.cache +/phpunit/files/ +/phpunit/config diff --git a/composer.json b/composer.json index 777ba242bb4..890d45dc23f 100644 --- a/composer.json +++ b/composer.json @@ -87,6 +87,7 @@ "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "^1.11", "phpstan/phpstan-deprecation-rules": "^1.2", + "phpunit/phpunit": "^9.6", "squizlabs/php_codesniffer": "^3.10", "symfony/browser-kit": "^5.4", "symfony/http-client": "^5.4", diff --git a/composer.lock b/composer.lock index df80854ce7a..52509b4bb9d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5990f1f9d41360a98165a63e9ac842c2", + "content-hash": "fb13663b1f3cb76299db3f21938395ae", "packages": [ { "name": "brick/math", @@ -5283,6 +5283,76 @@ }, "time": "2018-01-29T22:41:37+00:00" }, + { + "name": "doctrine/instantiator", + "version": "1.5.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^9 || ^11", + "ext-pdo": "*", + "ext-phar": "*", + "phpbench/phpbench": "^0.16 || ^1", + "phpstan/phpstan": "^1.4", + "phpstan/phpstan-phpunit": "^1", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "vimeo/psalm": "^4.30 || ^5.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "https://ocramius.github.io/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", + "keywords": [ + "constructor", + "instantiate" + ], + "support": { + "issues": "https://github.com/doctrine/instantiator/issues", + "source": "https://github.com/doctrine/instantiator/tree/1.5.0" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", + "type": "tidelift" + } + ], + "time": "2022-12-30T00:15:36+00:00" + }, { "name": "friendsoftwig/twigcs", "version": "v6.1.0", @@ -5525,6 +5595,66 @@ }, "time": "2022-02-23T02:02:42+00:00" }, + { + "name": "myclabs/deep-copy", + "version": "1.12.0", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3 <3.2.2" + }, + "require-dev": { + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpspec/prophecy": "^1.10", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" + }, + "type": "library", + "autoload": { + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2024-06-12T14:39:25+00:00" + }, { "name": "nikic/php-parser", "version": "v4.13.2", @@ -5547,19 +5677,1435 @@ "ircmaxell/php-yacc": "^0.0.7", "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" }, - "bin": [ - "bin/php-parse" - ], + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.2" + }, + "time": "2021-11-30T19:35:32+00:00" + }, + { + "name": "phar-io/manifest", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "54750ef60c58e43759730615a392c31c80e23176" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176", + "reference": "54750ef60c58e43759730615a392c31c80e23176", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-phar": "*", + "ext-xmlwriter": "*", + "phar-io/version": "^3.0.1", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:33:53+00:00" + }, + { + "name": "phar-io/version", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.2.1" + }, + "time": "2022-02-21T01:04:05+00:00" + }, + { + "name": "php-parallel-lint/php-parallel-lint", + "version": "v1.4.0", + "source": { + "type": "git", + "url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git", + "reference": "6db563514f27e19595a19f45a4bf757b6401194e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/6db563514f27e19595a19f45a4bf757b6401194e", + "reference": "6db563514f27e19595a19f45a4bf757b6401194e", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=5.3.0" + }, + "replace": { + "grogy/php-parallel-lint": "*", + "jakub-onderka/php-parallel-lint": "*" + }, + "require-dev": { + "nette/tester": "^1.3 || ^2.0", + "php-parallel-lint/php-console-highlighter": "0.* || ^1.0", + "squizlabs/php_codesniffer": "^3.6" + }, + "suggest": { + "php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet" + }, + "bin": [ + "parallel-lint" + ], + "type": "library", + "autoload": { + "classmap": [ + "./src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Jakub Onderka", + "email": "ahoj@jakubonderka.cz" + } + ], + "description": "This tool checks the syntax of PHP files about 20x faster than serial check.", + "homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint", + "keywords": [ + "lint", + "static analysis" + ], + "support": { + "issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues", + "source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/v1.4.0" + }, + "time": "2024-03-27T12:14:49+00:00" + }, + { + "name": "phpstan/extension-installer", + "version": "1.4.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "f6b87faf9fc7978eab2f7919a8760bc9f58f9203" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/f6b87faf9fc7978eab2f7919a8760bc9f58f9203", + "reference": "f6b87faf9fc7978eab2f7919a8760bc9f58f9203", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.4.1" + }, + "time": "2024-06-10T08:20:49+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "1.11.5", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "490f0ae1c92b082f154681d7849aee776a7c1443" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/490f0ae1c92b082f154681d7849aee776a7c1443", + "reference": "490f0ae1c92b082f154681d7849aee776a7c1443", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2024-06-17T15:10:54+00:00" + }, + { + "name": "phpstan/phpstan-deprecation-rules", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", + "reference": "fa8cce7720fa782899a0aa97b6a41225d1bb7b26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/fa8cce7720fa782899a0aa97b6a41225d1bb7b26", + "reference": "fa8cce7720fa782899a0aa97b6a41225d1bb7b26", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.11" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^9.5" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "support": { + "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.2.0" + }, + "time": "2024-04-20T06:39:48+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "9.2.15", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2e9da11878c4202f97915c1cb4bb1ca318a63f5f", + "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "nikic/php-parser": "^4.13.0", + "php": ">=7.3", + "phpunit/php-file-iterator": "^3.0.3", + "phpunit/php-text-template": "^2.0.2", + "sebastian/code-unit-reverse-lookup": "^2.0.2", + "sebastian/complexity": "^2.0", + "sebastian/environment": "^5.1.2", + "sebastian/lines-of-code": "^1.0.3", + "sebastian/version": "^3.0.1", + "theseer/tokenizer": "^1.2.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-pcov": "*", + "ext-xdebug": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.15" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2022-03-07T09:28:20+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "3.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2021-12-02T12:48:52+00:00" + }, + { + "name": "phpunit/php-invoker", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/5a10147d0aaf65b58940a0b72f71c9ac0423cc67", + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-pcntl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", + "keywords": [ + "process" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/3.1.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T05:58:55+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", + "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T05:33:50+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "5.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", + "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/5.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:16:10+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "9.6.11", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "810500e92855eba8a7a5319ae913be2da6f957b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/810500e92855eba8a7a5319ae913be2da6f957b0", + "reference": "810500e92855eba8a7a5319ae913be2da6f957b0", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.3.1 || ^2", + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.10.1", + "phar-io/manifest": "^2.0.3", + "phar-io/version": "^3.0.2", + "php": ">=7.3", + "phpunit/php-code-coverage": "^9.2.13", + "phpunit/php-file-iterator": "^3.0.5", + "phpunit/php-invoker": "^3.1.1", + "phpunit/php-text-template": "^2.0.3", + "phpunit/php-timer": "^5.0.2", + "sebastian/cli-parser": "^1.0.1", + "sebastian/code-unit": "^1.0.6", + "sebastian/comparator": "^4.0.8", + "sebastian/diff": "^4.0.3", + "sebastian/environment": "^5.1.3", + "sebastian/exporter": "^4.0.5", + "sebastian/global-state": "^5.0.1", + "sebastian/object-enumerator": "^4.0.3", + "sebastian/resource-operations": "^3.0.3", + "sebastian/type": "^3.2", + "sebastian/version": "^3.0.2" + }, + "suggest": { + "ext-soap": "To be able to generate mocks based on WSDL files", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.6-dev" + } + }, + "autoload": { + "files": [ + "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "security": "https://github.com/sebastianbergmann/phpunit/security/policy", + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.11" + }, + "funding": [ + { + "url": "https://phpunit.de/sponsors.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", + "type": "tidelift" + } + ], + "time": "2023-08-19T07:10:56+00:00" + }, + { + "name": "sebastian/cli-parser", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/2b56bea83a09de3ac06bb18b92f068e60cc6f50b", + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T06:27:43+00:00" + }, + { + "name": "sebastian/code-unit", + "version": "1.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/1fc9f64c0927627ef78ba436c9b17d967e68e120", + "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "source": "https://github.com/sebastianbergmann/code-unit/tree/1.0.8" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:08:54+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/2.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T05:30:19+00:00" + }, + { + "name": "sebastian/comparator", + "version": "4.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "fa0f136dd2334583309d32b62544682ee972b51a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/fa0f136dd2334583309d32b62544682ee972b51a", + "reference": "fa0f136dd2334583309d32b62544682ee972b51a", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/diff": "^4.0", + "sebastian/exporter": "^4.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.8" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2022-09-14T12:41:17+00:00" + }, + { + "name": "sebastian/complexity", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "739b35e53379900cc9ac327b2147867b8b6efd88" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/739b35e53379900cc9ac327b2147867b8b6efd88", + "reference": "739b35e53379900cc9ac327b2147867b8b6efd88", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.7", + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for calculating the complexity of PHP code units", + "homepage": "https://github.com/sebastianbergmann/complexity", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T15:52:27+00:00" + }, + { + "name": "sebastian/environment", + "version": "5.1.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-posix": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:03:51+00:00" + }, + { + "name": "sebastian/exporter", + "version": "4.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/78c00df8f170e02473b682df15bfcdacc3d32d72", + "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/recursion-context": "^4.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "https://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.6" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T06:33:00+00:00" + }, + { + "name": "sebastian/global-state", + "version": "5.0.7", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9", + "reference": "bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" + }, + "require-dev": { + "ext-dom": "*", + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.7" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T06:35:11+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.6", + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for counting the lines of code in PHP source code", + "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-28T06:42:11+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "4.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "5c9eeac41b290a3712d88851518825ad78f45c71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71", + "reference": "5c9eeac41b290a3712d88851518825ad78f45c71", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/4.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:12:34+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", + "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.9-dev" + "dev-master": "2.0-dev" } }, "autoload": { - "psr-4": { - "PhpParser\\": "lib/PhpParser" - } + "classmap": [ + "src/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -5567,229 +7113,249 @@ ], "authors": [ { - "name": "Nikita Popov" + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" } ], - "description": "A PHP parser written in PHP", - "keywords": [ - "parser", - "php" - ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", "support": { - "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.2" + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/2.0.4" }, - "time": "2021-11-30T19:35:32+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:14:26+00:00" }, { - "name": "php-parallel-lint/php-parallel-lint", - "version": "v1.4.0", + "name": "sebastian/recursion-context", + "version": "4.0.5", "source": { "type": "git", - "url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git", - "reference": "6db563514f27e19595a19f45a4bf757b6401194e" + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/6db563514f27e19595a19f45a4bf757b6401194e", - "reference": "6db563514f27e19595a19f45a4bf757b6401194e", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", "shasum": "" }, "require": { - "ext-json": "*", - "php": ">=5.3.0" - }, - "replace": { - "grogy/php-parallel-lint": "*", - "jakub-onderka/php-parallel-lint": "*" + "php": ">=7.3" }, "require-dev": { - "nette/tester": "^1.3 || ^2.0", - "php-parallel-lint/php-console-highlighter": "0.* || ^1.0", - "squizlabs/php_codesniffer": "^3.6" - }, - "suggest": { - "php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet" + "phpunit/phpunit": "^9.3" }, - "bin": [ - "parallel-lint" - ], "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, "autoload": { "classmap": [ - "./src/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-2-Clause" + "BSD-3-Clause" ], "authors": [ { - "name": "Jakub Onderka", - "email": "ahoj@jakubonderka.cz" + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" } ], - "description": "This tool checks the syntax of PHP files about 20x faster than serial check.", - "homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint", - "keywords": [ - "lint", - "static analysis" - ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "https://github.com/sebastianbergmann/recursion-context", "support": { - "issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues", - "source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/v1.4.0" + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.5" }, - "time": "2024-03-27T12:14:49+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:07:39+00:00" }, { - "name": "phpstan/extension-installer", - "version": "1.4.1", + "name": "sebastian/resource-operations", + "version": "3.0.4", "source": { "type": "git", - "url": "https://github.com/phpstan/extension-installer.git", - "reference": "f6b87faf9fc7978eab2f7919a8760bc9f58f9203" + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/f6b87faf9fc7978eab2f7919a8760bc9f58f9203", - "reference": "f6b87faf9fc7978eab2f7919a8760bc9f58f9203", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e", + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e", "shasum": "" }, "require": { - "composer-plugin-api": "^2.0", - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.9.0" + "php": ">=7.3" }, "require-dev": { - "composer/composer": "^2.0", - "php-parallel-lint/php-parallel-lint": "^1.2.0", - "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + "phpunit/phpunit": "^9.0" }, - "type": "composer-plugin", + "type": "library", "extra": { - "class": "PHPStan\\ExtensionInstaller\\Plugin" + "branch-alias": { + "dev-main": "3.0-dev" + } }, "autoload": { - "psr-4": { - "PHPStan\\ExtensionInstaller\\": "src/" - } + "classmap": [ + "src/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], - "description": "Composer plugin for automatic installation of PHPStan extensions", + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "support": { - "issues": "https://github.com/phpstan/extension-installer/issues", - "source": "https://github.com/phpstan/extension-installer/tree/1.4.1" + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.4" }, - "time": "2024-06-10T08:20:49+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-14T16:00:52+00:00" }, { - "name": "phpstan/phpstan", - "version": "1.11.5", + "name": "sebastian/type", + "version": "3.2.1", "source": { "type": "git", - "url": "https://github.com/phpstan/phpstan.git", - "reference": "490f0ae1c92b082f154681d7849aee776a7c1443" + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/490f0ae1c92b082f154681d7849aee776a7c1443", - "reference": "490f0ae1c92b082f154681d7849aee776a7c1443", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": ">=7.3" }, - "conflict": { - "phpstan/phpstan-shim": "*" + "require-dev": { + "phpunit/phpunit": "^9.5" }, - "bin": [ - "phpstan", - "phpstan.phar" - ], "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, "autoload": { - "files": [ - "bootstrap.php" + "classmap": [ + "src/" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], - "description": "PHPStan - PHP Static Analysis Tool", - "keywords": [ - "dev", - "static analysis" + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", "support": { - "docs": "https://phpstan.org/user-guide/getting-started", - "forum": "https://github.com/phpstan/phpstan/discussions", - "issues": "https://github.com/phpstan/phpstan/issues", - "security": "https://github.com/phpstan/phpstan/security/policy", - "source": "https://github.com/phpstan/phpstan-src" + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/3.2.1" }, "funding": [ { - "url": "https://github.com/ondrejmirtes", - "type": "github" - }, - { - "url": "https://github.com/phpstan", + "url": "https://github.com/sebastianbergmann", "type": "github" } ], - "time": "2024-06-17T15:10:54+00:00" + "time": "2023-02-03T06:13:03+00:00" }, { - "name": "phpstan/phpstan-deprecation-rules", - "version": "1.2.0", + "name": "sebastian/version", + "version": "3.0.2", "source": { "type": "git", - "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", - "reference": "fa8cce7720fa782899a0aa97b6a41225d1bb7b26" + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "c6c1022351a901512170118436c764e473f6de8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/fa8cce7720fa782899a0aa97b6a41225d1bb7b26", - "reference": "fa8cce7720fa782899a0aa97b6a41225d1bb7b26", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c", + "reference": "c6c1022351a901512170118436c764e473f6de8c", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.11" - }, - "require-dev": { - "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5" + "php": ">=7.3" }, - "type": "phpstan-extension", + "type": "library", "extra": { - "phpstan": { - "includes": [ - "rules.neon" - ] + "branch-alias": { + "dev-master": "3.0-dev" } }, "autoload": { - "psr-4": { - "PHPStan\\": "src/" - } + "classmap": [ + "src/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], - "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", "support": { - "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", - "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.2.0" + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/3.0.2" }, - "time": "2024-04-20T06:39:48+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T06:39:44+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -6324,6 +7890,56 @@ ], "time": "2024-06-28T09:36:24+00:00" }, + { + "name": "theseer/tokenizer", + "version": "1.2.3", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/1.2.3" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:36:25+00:00" + }, { "name": "webmozart/glob", "version": "4.5.0", diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 00000000000..c5248206942 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,12 @@ + + + + phpunit/functional/ + + + + diff --git a/phpunit/Autoload.php b/phpunit/Autoload.php new file mode 100644 index 00000000000..bd905309049 --- /dev/null +++ b/phpunit/Autoload.php @@ -0,0 +1,39 @@ +. + * + * --------------------------------------------------------------------- + */ + +class Autoload extends \DbTestCase +{ + //Placebo class to get autoloader tested +} diff --git a/phpunit/DbTestCase.php b/phpunit/DbTestCase.php new file mode 100644 index 00000000000..7deaa7bf308 --- /dev/null +++ b/phpunit/DbTestCase.php @@ -0,0 +1,310 @@ +. + * + * --------------------------------------------------------------------- + */ + +use Glpi\Toolbox\Sanitizer; + +// Generic test classe, to be extended for CommonDBTM Object + +class DbTestCase extends \GLPITestCase +{ + public function setUp(): void + { + global $DB; + $DB->beginTransaction(); + parent::setUp(); + } + + public function tearDown(): void + { + global $DB; + $DB->rollback(); + parent::tearDown(); + } + + + /** + * Connect (using the test user per default) + * + * @param string $user_name User name (defaults to TU_USER) + * @param string $user_pass user password (defaults to TU_PASS) + * @param bool $noauto disable autologin (from CAS by example) + * @param bool $expected bool result expected from login return + * + * @return \Auth + */ + protected function login( + string $user_name = TU_USER, + string $user_pass = TU_PASS, + bool $noauto = true, + bool $expected = true + ): \Auth { + \Session::destroy(); + \Session::start(); + + $auth = new Auth(); + $this->assertEquals($expected, $auth->login($user_name, $user_pass, $noauto)); + + return $auth; + } + + /** + * Log out current user + * + * @return void + */ + protected function logOut() + { + $ctime = $_SESSION['glpi_currenttime']; + \Session::destroy(); + $_SESSION['glpi_currenttime'] = $ctime; + } + + /** + * change current entity + * + * @param int|string $entityname Name of the entity (or its id) + * @param boolean $subtree Recursive load + * + * @return void + */ + protected function setEntity($entityname, $subtree) + { + $entity_id = is_int($entityname) ? $entityname : getItemByTypeName('Entity', $entityname, true); + $res = Session::changeActiveEntities($entity_id, $subtree); + $this->assertTrue($res); + } + + /** + * Generic method to test if an added object is corretly inserted + * + * @param Object $object The object to test + * @param int $id The id of added object + * @param array $input the input used for add object (optionnal) + * + * @return void + */ + protected function checkInput(CommonDBTM $object, $id = 0, $input = []) + { + $input = Sanitizer::dbUnescapeRecursive($input); // slashes in input should not be stored in DB + + $this->assertGreaterThan(0, (int)$id); + $this->assertTrue($object->getFromDB($id)); + $this->assertEquals($id, $object->getField('id')); + + if (count($input)) { + foreach ($input as $k => $v) { + $this->assertEquals( + $v, + $object->fields[$k], + " + '$k' key current value '{$object->fields[$k]}' (" . gettype($object->fields[$k]) . ") + is not equal to '$v' (" . gettype($v) . ")" + ); + } + } + } + + /** + * Get all classes in folder inc/ + * + * @param boolean $function Whether to look for a function + * @param array $excludes List of classes to exclude + * + * @return array + */ + protected function getClasses($function = false, array $excludes = []) + { + // Add deprecated classes to excludes to prevent test failure + $excludes = array_merge( + $excludes, + [ + 'TicketFollowup', // Deprecated + '/^RuleImportComputer.*/', // Deprecated + ] + ); + + $files_iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator(GLPI_ROOT . '/src'), + RecursiveIteratorIterator::SELF_FIRST + ); + + $classes = []; + foreach ($files_iterator as $fileInfo) { + if ($fileInfo->getExtension() !== 'php') { + continue; + } + + $classname = $fileInfo->getBasename('.php'); + + $is_excluded = false; + foreach ($excludes as $exclude) { + if ($classname === $exclude || @preg_match($exclude, $classname) === 1) { + $is_excluded = true; + break; + } + } + if ($is_excluded) { + continue; + } + + if (!class_exists($classname)) { + continue; + } + $reflectionClass = new ReflectionClass($classname); + if ($reflectionClass->isAbstract()) { + continue; + } + + if ($function) { + if (method_exists($classname, $function)) { + $classes[] = $classname; + } + } else { + $classes[] = $classname; + } + } + return array_unique($classes); + } + + /** + * Create an item of the given class + * + * @param string $itemtype + * @param array $input + * @param array $skip_fields Fields that wont be checked after creation + * + * @return CommonDBTM + */ + protected function createItem($itemtype, $input, $skip_fields = []): CommonDBTM + { + $item = new $itemtype(); + $input = Sanitizer::sanitize($input); + $id = $item->add($input); + $this->assertIsInt($id); + $this->assertGreaterThan(0, $id); + + // Remove special fields + $skip_fields[] = 'id'; + $input = array_filter($input, function ($key) use ($skip_fields) { + return !in_array($key, $skip_fields) && strpos($key, '_') !== 0; + }, ARRAY_FILTER_USE_KEY); + + $this->checkInput($item, $id, $input); + + return $item; + } + + /** + * Create an item of the given class + * + * @param string $itemtype + * @param array $input + * @param array $skip_fields Fields that wont be checked after update + */ + protected function updateItem($itemtype, $id, $input, $skip_fields = []) + { + $item = new $itemtype(); + $input['id'] = $id; + $input = Sanitizer::sanitize($input); + $success = $item->update($input); + $this->assertTrue($success); + + // Remove special fields + $input = array_filter($input, function ($key) use ($skip_fields) { + return !in_array($key, $skip_fields) && strpos($key, '_') !== 0; + }, ARRAY_FILTER_USE_KEY); + + $this->checkInput($item, $id, $input); + } + + /** + * Create multiples items of the given class + * + * @param string $itemtype + * @param array $inputs + * + * @return array created items + */ + protected function createItems($itemtype, $inputs): array + { + $items = []; + foreach ($inputs as $input) { + $items[] = $this->createItem($itemtype, $input); + } + + return $items; + } + + /** + * Helper method to avoid writting the same boilerplate code for rule creation + * + * @param RuleBuilder $builder RuleConfiguration + * + * @return Rule Created rule + */ + protected function createRule(RuleBuilder $builder): Rule + { + /** @var Rule $rule */ + $rule = $this->createItem(RuleTicket::class, [ + 'is_active' => 1, + 'sub_type' => 'RuleTicket', + 'name' => $builder->getName(), + 'match' => $builder->getOperator(), + 'condition' => $builder->getCondition(), + 'is_recursive' => $builder->isRecursive(), + 'entities_id' => $builder->getEntity(), + ]); + + foreach ($builder->getCriteria() as $criterion) { + $this->createItem(RuleCriteria::class, [ + 'rules_id' => $rule->getID(), + 'criteria' => $criterion['criteria'], + 'condition' => $criterion['condition'], + 'pattern' => $criterion['pattern'], + ]); + } + + foreach ($builder->getActions() as $criterion) { + $this->createItem(RuleAction::class, [ + 'rules_id' => $rule->getID(), + 'action_type' => $criterion['action_type'], + 'field' => $criterion['field'], + 'value' => $criterion['value'], + ]); + } + + return $rule; + } +} diff --git a/phpunit/GLPITestCase.php b/phpunit/GLPITestCase.php new file mode 100644 index 00000000000..c19227b1083 --- /dev/null +++ b/phpunit/GLPITestCase.php @@ -0,0 +1,331 @@ +. + * + * --------------------------------------------------------------------- + */ + +use Glpi\Tests\Log\TestHandler; +use Monolog\Logger; +use PHPUnit\Framework\TestCase; +use Psr\Log\LogLevel; + +// Main GLPI test case. All tests should extends this class. + +class GLPITestCase extends TestCase +{ + private $int; + private $str; + protected $has_failed = false; + + /** + * @var TestHandler + */ + private $php_log_handler; + + /** + * @var TestHandler + */ + private $sql_log_handler; + + public function setUp(): void + { + // By default, no session, not connected + $this->resetSession(); + + // Ensure cache is clear + global $GLPI_CACHE; + $GLPI_CACHE->clear(); + + // Init log handlers + global $PHPLOGGER, $SQLLOGGER; + /** @var Monolog\Logger $PHPLOGGER */ + $this->php_log_handler = new TestHandler(LogLevel::DEBUG); + $PHPLOGGER->setHandlers([$this->php_log_handler]); + $this->sql_log_handler = new TestHandler(LogLevel::DEBUG); + $SQLLOGGER->setHandlers([$this->sql_log_handler]); + } + + public function tearDown(): void + { + if (isset($_SESSION['MESSAGE_AFTER_REDIRECT']) && !$this->has_failed) { + unset($_SESSION['MESSAGE_AFTER_REDIRECT'][INFO]); + $this->assertSame( + [], + $_SESSION['MESSAGE_AFTER_REDIRECT'], + sprintf( + "Some messages has not been handled in %s::%s:\n%s", + static::class, + __METHOD__/*$method*/, + print_r($_SESSION['MESSAGE_AFTER_REDIRECT'], true) + ) + ); + } + + if (!$this->has_failed) { + foreach ([$this->php_log_handler, $this->sql_log_handler] as $log_handler) { + $this->assertEmpty( + $log_handler->getRecords(), + sprintf( + "Unexpected entries in log in %s::%s:\n%s", + static::class, + __METHOD__/*$method*/, + print_r(array_column($log_handler->getRecords(), 'message'), true) + ) + ); + } + } + } + + /** + * Call a private method, and get its return value. + * + * @param mixed $instance Class instance + * @param string $methodName Method to call + * @param mixed ...$arg Method arguments + * + * @return mixed + */ + protected function callPrivateMethod($instance, string $methodName, ...$args) + { + $method = new \ReflectionMethod($instance, $methodName); + $method->setAccessible(true); + + return $method->invoke($instance, ...$args); + } + + protected function resetSession() + { + Session::destroy(); + Session::start(); + + $_SESSION['glpi_use_mode'] = Session::NORMAL_MODE; + $_SESSION['glpiactive_entity'] = 0; + + global $CFG_GLPI; + foreach ($CFG_GLPI['user_pref_field'] as $field) { + if (!isset($_SESSION["glpi$field"]) && isset($CFG_GLPI[$field])) { + $_SESSION["glpi$field"] = $CFG_GLPI[$field]; + } + } + } + + protected function hasSessionMessages(int $level, array $messages): void + { + $this->has_failed = true; + $this->assertTrue( + isset($_SESSION['MESSAGE_AFTER_REDIRECT'][$level]), + 'No messages for selected level!' + ); + $this->assertSame( + $messages, + $_SESSION['MESSAGE_AFTER_REDIRECT'][$level], + 'Expecting ' . print_r($messages, true) . 'got: ' . print_r($_SESSION['MESSAGE_AFTER_REDIRECT'][$level], true) + ); + unset($_SESSION['MESSAGE_AFTER_REDIRECT'][$level]); //reset + $this->has_failed = false; + } + + protected function hasNoSessionMessages(array $levels) + { + foreach ($levels as $level) { + $this->hasNoSessionMessage($level); + } + } + + protected function hasNoSessionMessage(int $level) + { + $this->has_failed = true; + $this->assertFalse( + isset($_SESSION['MESSAGE_AFTER_REDIRECT'][$level]), + sprintf( + 'Messages for level %s are present in session: %s', + $level, + print_r($_SESSION['MESSAGE_AFTER_REDIRECT'][$level] ?? [], true) + ) + ); + $this->has_failed = false; + } + + /** + * Check in PHP log for a record that contains given message. + * + * @param string $message + * @param string $level + * + * @return void + */ + protected function hasPhpLogRecordThatContains(string $message, string $level): void + { + $this->hasLogRecordThatContains($this->php_log_handler, $message, $level); + } + + /** + * Check in SQL log for a record that contains given message. + * + * @param string $message + * @param string $level + * + * @return void + */ + protected function hasSqlLogRecordThatContains(string $message, string $level): void + { + $this->hasLogRecordThatContains($this->sql_log_handler, $message, $level); + } + + /** + * Check given log handler for a record that contains given message. + * + * @param string $message + * @param string $level + * + * @return void + */ + private function hasLogRecordThatContains(TestHandler $handler, string $message, string $level): void + { + $this->has_failed = true; + + $records = array_map( + function ($record) { + // Keep only useful info to display a comprehensive dump + return [ + 'level' => $record['level'], + 'message' => $record['message'], + ]; + }, + $handler->getRecords() + ); + + $matching = null; + foreach ($records as $record) { + if ($record['level'] === Logger::toMonologLevel($level) && strpos($record['message'], $message) !== false) { + $matching = $record; + break; + } + } + $this->assertNotNull( + $matching, + sprintf("Message not found in log records\n- %s\n+ %s", $message, print_r($records, true)) + ); + + $handler->dropFromRecords($matching['message'], $matching['level']); + + $this->has_failed = false; + } + + /** + * Check in PHP log for a record that matches given pattern. + * + * @param string $message + * @param string $level + * + * @return void + */ + protected function hasPhpLogRecordThatMatches(string $pattern, string $level): void + { + $this->hasLogRecordThatMatches($this->php_log_handler, $pattern, $level); + } + + /** + * Check in SQL log for a record that matches given pattern. + * + * @param string $message + * @param string $level + * + * @return void + */ + protected function hasSqlLogRecordThatMatches(string $pattern, string $level): void + { + $this->hasLogRecordThatMatches($this->sql_log_handler, $pattern, $level); + } + + /** + * Check given log handler for a record that matches given pattern. + * + * @param string $message + * @param string $level + * + * @return void + */ + private function hasLogRecordThatMatches(TestHandler $handler, string $pattern, string $level): void + { + $this->has_failed = true; + + $matching = null; + foreach ($handler->getRecords() as $record) { + if ($record['level'] === Logger::toMonologLevel($level) && preg_match($pattern, $record['message']) === 1) { + $matching = $record; + break; + } + } + $this->assertNotNull( + $matching, + 'No matching log found.' + ); + $handler->dropFromRecords($matching['message'], $matching['level']); + + $this->has_failed = false; + } + + /** + * Get a unique random string + */ + protected function getUniqueString() + { + if (is_null($this->str)) { + return $this->str = uniqid('str'); + } + return $this->str .= 'x'; + } + + /** + * Get a unique random integer + */ + protected function getUniqueInteger() + { + if (is_null($this->int)) { + return $this->int = mt_rand(1000, 10000); + } + return $this->int++; + } + + /** + * Get the "_test_root_entity" entity created by the tests's bootstrap file + * + * @param bool $only_id + * + * @return Entity|int + */ + protected function getTestRootEntity(bool $only_id = false) + { + return getItemByTypeName('Entity', '_test_root_entity', $only_id); + } +} diff --git a/tests/InventoryTestCase.php b/phpunit/InventoryTestCase.php similarity index 85% rename from tests/InventoryTestCase.php rename to phpunit/InventoryTestCase.php index 9863cf3dcf4..7a7f0843c82 100644 --- a/tests/InventoryTestCase.php +++ b/phpunit/InventoryTestCase.php @@ -47,9 +47,9 @@ class InventoryTestCase extends \DbTestCase /** @var int */ protected int $nblogs; - public function beforeTestMethod($method) + public function setUp(): void { - parent::beforeTestMethod($method); + parent::setUp(); $this->nblogs = countElementsInTable(\Log::getTable()); @@ -63,13 +63,13 @@ public function beforeTestMethod($method) } } - public function afterTestMethod($method) + public function tearDown(): void { global $DB; - parent::afterTestMethod($method); - if (str_starts_with($method, 'testImport')) { - //$this->dump('Checking for unexpected logs'); + parent::tearDown(); + + if (str_starts_with($this->getName(), 'testImport')) { $nblogsnow = countElementsInTable(\Log::getTable()); $logs = $DB->request([ 'FROM' => \Log::getTable(), @@ -86,17 +86,21 @@ public function afterTestMethod($method) ] ] ]); - $this->integer(count($logs))->isIdenticalTo(0, print_r(iterator_to_array($logs), true)); + $this->assertSame( + 0, + count($logs), + print_r(iterator_to_array($logs), true) + ); } - if (str_starts_with($method, 'testUpdate')) { + if (str_starts_with($this->getName(), 'testUpdate')) { $nblogsnow = countElementsInTable(\Log::getTable()); $logs = $DB->request([ 'FROM' => \Log::getTable(), 'LIMIT' => $nblogsnow, 'OFFSET' => $this->nblogs, ]); - $this->integer(count($logs))->isIdenticalTo(0/*, print_r(iterator_to_array($logs), true)*/); + $this->assertSame(0, count($logs)); } $files = new \RecursiveIteratorIterator( @@ -134,8 +138,8 @@ protected function doInventory($source, bool $is_xml = false) if ($inventory->inError()) { $this->dump($inventory->getErrors()); } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isEmpty(); + $this->assertFalse($inventory->inError()); + $this->assertEmpty($inventory->getErrors()); return $inventory; } diff --git a/tests/abstracts/AbstractInventoryAsset.php b/phpunit/abstracts/AbstractInventoryAsset.php similarity index 76% rename from tests/abstracts/AbstractInventoryAsset.php rename to phpunit/abstracts/AbstractInventoryAsset.php index 424bfb87eaa..761703d5b40 100644 --- a/tests/abstracts/AbstractInventoryAsset.php +++ b/phpunit/abstracts/AbstractInventoryAsset.php @@ -42,17 +42,17 @@ abstract class AbstractInventoryAsset extends \InventoryTestCase protected $log_entries; protected $new_log_entries = 0; - public function beforeTestMethod($method) + public function setUp(): void { - parent::beforeTestMethod($method); + parent::setUp(); $this->log_entries = countElementsInTable(\Log::getTable()); } - public function afterTestMethod($method) + public function tearDown(): void { - parent::afterTestMethod($method); + parent::tearDown(); $log_entries = countElementsInTable(\Log::getTable()); - $this->integer($log_entries)->isIdenticalTo($this->log_entries + $this->new_log_entries); + $this->assertSame($this->log_entries + $this->new_log_entries, $log_entries); } /** @@ -60,14 +60,5 @@ public function afterTestMethod($method) * * @return array */ - abstract protected function assetProvider(): array; - - /** - * Test asset preparation - * - * @param array $json JSON asset data - * - * @return void - */ - //abstract public function testPrepare($json, $asset); + abstract public static function assetProvider(): array; } diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php new file mode 100644 index 00000000000..7f5161b9699 --- /dev/null +++ b/phpunit/bootstrap.php @@ -0,0 +1,111 @@ +. + * + * --------------------------------------------------------------------- + */ + +use Glpi\Application\ErrorHandler; +use Glpi\Cache\CacheManager; +use Glpi\Cache\SimpleCache; +use Symfony\Component\Cache\Adapter\ArrayAdapter; + +// Ensure errors happening during test suite bootstraping are always displayed +ini_set('display_errors', 'On'); +error_reporting(E_ALL); + +define('GLPI_ROOT', __DIR__ . '/../'); +define('GLPI_CONFIG_DIR', getenv('GLPI_CONFIG_DIR') ?: __DIR__ . '/config'); +define('GLPI_VAR_DIR', getenv('GLPI_VAR_DIR') ?: __DIR__ . '/files'); +define('GLPI_URI', getenv('GLPI_URI') ?: 'http://localhost:8088'); +define('GLPI_STRICT_DEPRECATED', true); //enable strict depreciations + +define( + 'PLUGINS_DIRECTORIES', + [ + GLPI_ROOT . '/plugins', + GLPI_ROOT . '/tests/fixtures/plugins', + ] +); + +define( + 'GLPI_SERVERSIDE_URL_ALLOWLIST', + [ + '/^(https?|feed):\/\/[^@:]+(\/.*)?$/', // default allowlist entry + '/^file:\/\/.*\.ics$/', // calendar mockups + ] +); + +define('TU_USER', '_test_user'); +define('TU_PASS', 'PhpUnit_4'); + +global $CFG_GLPI, $GLPI_CACHE; + +include(GLPI_ROOT . "/inc/based_config.php"); + +if (!file_exists(GLPI_CONFIG_DIR . '/config_db.php')) { + die("\nConfiguration file for tests not found\n\nrun: php bin/console database:install --config-dir=" . GLPI_CONFIG_DIR . " ...\n\n"); +} + +\Glpi\Tests\BootstrapUtils::initVarDirectories(); + +include_once __DIR__ . '/../inc/includes.php'; + +//init cache +if (file_exists(GLPI_CONFIG_DIR . DIRECTORY_SEPARATOR . CacheManager::CONFIG_FILENAME)) { + // Use configured cache for cache tests + $cache_manager = new CacheManager(); + $GLPI_CACHE = $cache_manager->getCoreCacheInstance(); +} else { + // Use "in-memory" cache for other tests + $GLPI_CACHE = new SimpleCache(new ArrayAdapter()); +} + +include_once __DIR__ . '/GLPITestCase.php'; +include_once __DIR__ . '/DbTestCase.php'; +//include_once __DIR__ . '/CsvTestCase.php'; +//include_once __DIR__ . '/APIBaseClass.php'; +//include_once __DIR__ . '/FrontBaseClass.php'; +include_once __DIR__ . '/InventoryTestCase.php'; +//include_once __DIR__ . '/functional/CommonITILRecurrent.php'; +//include_once __DIR__ . '/functional/Glpi/ContentTemplates/Parameters/AbstractParameters.php'; +//include_once __DIR__ . '/functional/AbstractRightsDropdown.php'; + +// check folder exists instead of class_exists('\GuzzleHttp\Client'), to prevent global includes +if (file_exists(__DIR__ . '/../vendor/autoload.php') && !file_exists(__DIR__ . '/../vendor/guzzlehttp/guzzle')) { + die("\nDevelopment dependencies not found\n\nrun: composer install -o\n\n"); +} + +loadDataset(); + +// There is no need to pollute the output with error messages. +ini_set('display_errors', 'Off'); +ErrorHandler::getInstance()->disableOutput(); diff --git a/tests/functional/Autoload.php b/phpunit/functional/AutoloadTest.php similarity index 85% rename from tests/functional/Autoload.php rename to phpunit/functional/AutoloadTest.php index a87916da3cb..6c620f71a89 100644 --- a/tests/functional/Autoload.php +++ b/phpunit/functional/AutoloadTest.php @@ -41,9 +41,9 @@ /* Test for inc/autoload.function.php */ -class Autoload extends DbTestCase +class AutoloadTest extends DbTestCase { - public function dataItemType() + public static function dataItemType(): array { return [ ['Computer', false, false], @@ -64,13 +64,15 @@ public function testIsPluginItemType($type, $plug, $class) { $res = isPluginItemType($type); if ($plug) { - $this->array($res) - ->isIdenticalTo([ - 'plugin' => $plug, - 'class' => $class - ]); + $this->assertSame( + [ + 'plugin' => $plug, + 'class' => $class + ], + $res + ); } else { - $this->boolean($res)->isFalse; + $this->assertFalse($res); } } @@ -79,6 +81,6 @@ public function testIsPluginItemType($type, $plug, $class) */ public function testAutoloadGlpiEvent() { - $this->boolean(class_exists('Glpi\\Event'))->isTrue(); + $this->assertTrue(class_exists('Glpi\\Event')); } } diff --git a/tests/functional/GLPIMailer.php b/phpunit/functional/GLPIMailer.php similarity index 91% rename from tests/functional/GLPIMailer.php rename to phpunit/functional/GLPIMailer.php index 97950d23856..81d61d70e19 100644 --- a/tests/functional/GLPIMailer.php +++ b/phpunit/functional/GLPIMailer.php @@ -41,7 +41,7 @@ class GLPIMailer extends DbTestCase { - protected function valideAddressProvider() + public static function valideAddressProvider() { return [ // Test local part @@ -78,7 +78,7 @@ public function testValidateAddress($address, $is_valid) { $mailer = new \GLPIMailer(); - $this->boolean($mailer->validateAddress($address))->isEqualTo($is_valid); + $this->assertEquals($is_valid, $mailer->validateAddress($address)); } public function testPhpMailerLang() @@ -87,10 +87,10 @@ public function testPhpMailerLang() $mailer->setLanguage(); $tr = $mailer->getTranslations(); - $this->string($tr['empty_message'])->isIdenticalTo('Message body empty'); + $this->assertSame('Message body empty', $tr['empty_message']); $mailer->setLanguage('fr'); $tr = $mailer->getTranslations(); - $this->string($tr['empty_message'])->isIdenticalTo('Corps du message vide.'); + $this->assertSame('Corps du message vide.', $tr['empty_message']); } } diff --git a/tests/functional/GLPI.php b/phpunit/functional/GLPITest.php similarity index 91% rename from tests/functional/GLPI.php rename to phpunit/functional/GLPITest.php index 652f90b84e2..2d6f5e6b962 100644 --- a/tests/functional/GLPI.php +++ b/phpunit/functional/GLPITest.php @@ -35,9 +35,9 @@ namespace tests\units; -/* Test for inc/glpi.class.php */ +use GLPITestCase; -class GLPI extends \GLPITestCase +class GLPITest extends GLPITestCase { public function testMissingLanguages() { @@ -55,12 +55,14 @@ public function testMissingLanguages() } $po_missing = array_diff_key($know_languages, $list_languages); - $this->array($po_missing)->isEmpty( + $this->assertEmpty( + $po_missing, "Referenced languages in configuration are missing in locales directory:\n" . print_r($po_missing, true) ); $cfg_missing = array_diff_key($list_languages, $know_languages); - $this->array($cfg_missing)->isEmpty( + $this->assertEmpty( + $cfg_missing, "Locales files present in directory are missing from configuration:\n" . print_r($cfg_missing, true) ); } @@ -72,6 +74,6 @@ public function testMissingLanguages() */ public function test_GlpiYear(): void { - $this->string(GLPI_YEAR)->isEqualTo(date('Y')); + $this->assertEquals(GLPI_YEAR, date('Y')); } } diff --git a/tests/functional/Glpi/Cache/CacheManager.php b/phpunit/functional/Glpi/Cache/CacheManager.php similarity index 62% rename from tests/functional/Glpi/Cache/CacheManager.php rename to phpunit/functional/Glpi/Cache/CacheManager.php index f040374f084..27e22f04fc3 100644 --- a/tests/functional/Glpi/Cache/CacheManager.php +++ b/phpunit/functional/Glpi/Cache/CacheManager.php @@ -35,15 +35,19 @@ namespace tests\units\Glpi\Cache; +use Monolog\Logger; use org\bovigo\vfs\vfsStream; use Psr\SimpleCache\CacheInterface; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Adapter\MemcachedAdapter; use Symfony\Component\Cache\Adapter\RedisAdapter; +/** + * @backupStaticAttributes disabled + */ class CacheManager extends \GLPITestCase { - protected function contextProvider(): iterable + public static function contextProvider(): iterable { yield [ 'context' => 'tempcache', @@ -77,64 +81,59 @@ protected function contextProvider(): iterable */ public function testIsContextValid(string $context, bool $is_valid, bool $is_configurable): void { - vfsStream::setup('glpi', null, ['config' => [], 'files' => ['_cache' => []]]); - $this->newTestedInstance(vfsStream::url('glpi/config'), vfsStream::url('glpi/files/_cache')); + $instance = new \Glpi\Cache\CacheManager( + vfsStream::url('glpi/config'), + vfsStream::url('glpi/files/_cache') + ); - $this->boolean($this->testedInstance->isContextValid($context, false))->isEqualTo($is_valid); - $this->boolean($this->testedInstance->isContextValid($context, true))->isEqualTo($is_valid && $is_configurable); + $this->assertEquals($is_valid, $instance->isContextValid($context, false)); + $this->assertEquals($is_valid && $is_configurable, $instance->isContextValid($context, true)); - // Also test argument checks on other methods + // Also test argument checks on other methods if (!$is_configurable) { $exception_msg = sprintf('Invalid or non configurable context: "%s".', $context); - $this->exception( - function () use ($context) { - $this->testedInstance->setConfiguration($context, 'memcached://localhost'); - } - )->message->isEqualTo($exception_msg); - - $this->exception( - function () use ($context) { - $this->testedInstance->unsetConfiguration($context); - } - )->message->isEqualTo($exception_msg); + $this->expectExceptionMessage($exception_msg); + $instance->setConfiguration($context, 'memcached://localhost'); + + $this->expectExceptionMessage($exception_msg); + $instance->unsetConfiguration($context); } else { - $this->boolean($this->testedInstance->setConfiguration($context, 'memcached://localhost'))->isTrue(); - $this->boolean($this->testedInstance->unsetConfiguration($context))->isTrue(); + $this->assertTrue($instance->setConfiguration($context, 'memcached://localhost')); + $this->assertTrue($instance->unsetConfiguration($context)); } if (!$is_valid) { $exception_msg = sprintf('Invalid context: "%s".', $context); - $this->exception( - function () use ($context) { - $this->testedInstance->getCacheInstance($context); - } - )->message->isEqualTo($exception_msg); + $this->expectExceptionMessage($exception_msg); + $instance->getCacheInstance($context); } else { - $this->object($this->testedInstance->getCacheInstance($context))->isInstanceOf(CacheInterface::class); + $this->assertInstanceOf(CacheInterface::class, $instance->getCacheInstance($context)); } } public function testGetNonConfigurableCache(): void { - vfsStream::setup('glpi', null, ['config' => [], 'files' => ['_cache' => []]]); - $this->newTestedInstance(vfsStream::url('glpi/config'), vfsStream::url('glpi/files/_cache')); + $instance = new \Glpi\Cache\CacheManager( + vfsStream::url('glpi/config'), + vfsStream::url('glpi/files/_cache') + ); - // Test 'installer' context - $this->object($this->testedInstance->getInstallerCacheInstance())->isInstanceOf(CacheInterface::class); - $this->object($this->testedInstance->getCacheInstance('installer'))->isInstanceOf(CacheInterface::class); - $this->object($this->testedInstance->getCacheStorageAdapter('installer'))->isInstanceOf(FilesystemAdapter::class); + // Test 'installer' context + $this->assertInstanceOf(CacheInterface::class, $instance->getInstallerCacheInstance()); + $this->assertInstanceOf(CacheInterface::class, $instance->getCacheInstance('installer')); + $this->assertInstanceOf(FilesystemAdapter::class, $instance->getCacheStorageAdapter('installer')); - // Test 'translations' context - $this->object($this->testedInstance->getTranslationsCacheInstance())->isInstanceOf(CacheInterface::class); - $this->object($this->testedInstance->getCacheInstance('translations'))->isInstanceOf(CacheInterface::class); - $this->object($this->testedInstance->getCacheStorageAdapter('translations'))->isInstanceOf(FilesystemAdapter::class); + // Test 'translations' context + $this->assertInstanceOf(CacheInterface::class, $instance->getTranslationsCacheInstance()); + $this->assertInstanceOf(CacheInterface::class, $instance->getCacheInstance('translations')); + $this->assertInstanceOf(FilesystemAdapter::class, $instance->getCacheStorageAdapter('translations')); } - protected function configurationProvider(): iterable + public static function configurationProvider(): iterable { foreach (['core', 'plugin:tester'] as $context) { // Invalid unique DSN @@ -143,7 +142,10 @@ protected function configurationProvider(): iterable 'dsn' => 'whoot://invalid', 'options' => [], 'expected_set_error' => 'Invalid DSN: "whoot://invalid".', - 'expected_get_error' => sprintf('Invalid configuration for cache context "%s".', $context), + 'expected_get_error' => [ + 'level' => Logger::WARNING, + 'message' => sprintf('Invalid configuration for cache context "%s".', $context) + ], 'expected_adapter' => FilesystemAdapter::class, // Fallback adapter ]; @@ -153,7 +155,10 @@ protected function configurationProvider(): iterable 'dsn' => ['redis://cache1.glpi-project.org', 'redis://cache2.glpi-project.org'], 'options' => [], 'expected_set_error' => 'Invalid DSN: ["redis://cache1.glpi-project.org","redis://cache2.glpi-project.org"].', - 'expected_get_error' => sprintf('Invalid configuration for cache context "%s".', $context), + 'expected_get_error' => [ + 'level' => Logger::WARNING, + 'message' => sprintf('Invalid configuration for cache context "%s".', $context) + ], 'expected_adapter' => FilesystemAdapter::class, // Fallback adapter ]; @@ -208,7 +213,10 @@ protected function configurationProvider(): iterable 'dsn' => 'whoot://invalid', 'options' => [], 'expected_set_error' => sprintf('Invalid or non configurable context: "%s".', $context), - 'expected_get_error' => sprintf('Invalid or non configurable context: "%s".', $context), + 'expected_get_error' => [ + 'level' => Logger::NOTICE, + 'message' => sprintf('Invalid or non configurable context: "%s".', $context) + ], 'expected_adapter' => FilesystemAdapter::class, // Fallback adapter ]; } @@ -222,27 +230,26 @@ public function testSetConfiguration( $dsn, array $options, ?string $expected_set_error, - ?string $expected_get_error, + ?array $expected_get_error, ?string $expected_adapter ): void { vfsStream::setup('glpi', null, ['config' => [], 'files' => ['_cache' => []]]); - $this->newTestedInstance(vfsStream::url('glpi/config'), vfsStream::url('glpi/files/_cache')); + $instance = new \Glpi\Cache\CacheManager( + vfsStream::url('glpi/config'), + vfsStream::url('glpi/files/_cache') + ); if ($expected_set_error !== null) { - $this->exception( - function () use ($context, $dsn, $options) { - $this->testedInstance->setConfiguration($context, $dsn, $options); - } - )->message->isEqualTo($expected_set_error); + $this->expectExceptionMessage($expected_set_error); + $instance->setConfiguration($context, $dsn, $options); return; } - $this->boolean($this->testedInstance->setConfiguration($context, $dsn, $options))->isTrue(); + $this->assertTrue($instance->setConfiguration($context, $dsn, $options)); $config_file = vfsStream::url('glpi/config/' . \Glpi\Cache\CacheManager::CONFIG_FILENAME); - $expected_config = [ 'contexts' => [ $context => [ @@ -252,8 +259,8 @@ function () use ($context, $dsn, $options) { ], ]; - $this->boolean(file_exists($config_file))->isTrue(); - $this->array(include($config_file))->isEqualTo($expected_config); + $this->assertTrue(file_exists($config_file)); + $this->assertEquals($expected_config, include($config_file)); } public function testUnsetConfiguration(): void @@ -289,28 +296,29 @@ public function testUnsetConfiguration(): void $config_file = vfsStream::url('glpi/config/' . $config_filename); - $this->newTestedInstance(vfsStream::url('glpi/config'), vfsStream::url('glpi/files/_cache')); + $instance = new \Glpi\Cache\CacheManager( + vfsStream::url('glpi/config'), + vfsStream::url('glpi/files/_cache') + ); - // Unsetting an invalid context does not alter config file - $this->exception( - function () { - $this->testedInstance->unsetConfiguration('notavalidcontext'); - } - )->message->isEqualTo('Invalid or non configurable context: "notavalidcontext".'); - $this->boolean(file_exists($config_file))->isTrue(); - $this->array(include($config_file))->isEqualTo($expected_config); + // Unsetting an invalid context does not alter config file + $this->expectExceptionMessage('Invalid or non configurable context: "notavalidcontext".'); + $instance->unsetConfiguration('notavalidcontext'); - // Unsetting core config only removes core entry in config file - $this->boolean($this->testedInstance->unsetConfiguration('core'))->isTrue(); + $this->assertTrue(file_exists($config_file)); + $this->assertEquals($expected_config, include($config_file)); + + // Unsetting core config only removes core entry in config file + $this->assertTrue($instance->unsetConfiguration('core')); unset($expected_config['contexts']['core']); - $this->boolean(file_exists($config_file))->isTrue(); - $this->array(include($config_file))->isEqualTo($expected_config); + $this->assertTrue(file_exists($config_file)); + $this->assertEquals($expected_config, include($config_file)); - // Unsetting a plugin config only removes this plugin entry in config file - $this->boolean($this->testedInstance->unsetConfiguration('plugin:tester'))->isTrue(); + // Unsetting a plugin config only removes this plugin entry in config file + $this->assertTrue($instance->unsetConfiguration('plugin:tester')); unset($expected_config['contexts']['plugin:tester']); - $this->boolean(file_exists($config_file))->isTrue(); - $this->array(include($config_file))->isEqualTo($expected_config); + $this->assertTrue(file_exists($config_file)); + $this->assertEquals($expected_config, include($config_file)); } /** @@ -321,7 +329,7 @@ public function testGetConfigurableCache( $dsn, array $options, ?string $expected_set_error, - ?string $expected_get_error, + ?array $expected_get_error, ?string $expected_adapter ): void { @@ -345,25 +353,23 @@ public function testGetConfigurableCache( ] ); - $this->newTestedInstance(vfsStream::url('glpi/config'), vfsStream::url('glpi/files/_cache')); + $instance = new \Glpi\Cache\CacheManager( + vfsStream::url('glpi/config'), + vfsStream::url('glpi/files/_cache') + ); if ($expected_get_error !== null) { - $this->when( - function () use ($context) { - $this->testedInstance->getCacheInstance($context); - } - )->error() - ->withMessage($expected_get_error) - ->exists(); + $this->assertInstanceOf(\Glpi\Cache\SimpleCache::class, $instance->getCacheInstance($context)); + $this->hasPhpLogRecordThatContains($expected_get_error['message'], $expected_get_error['level']); return; } - $this->object($this->testedInstance->getCacheInstance($context))->isInstanceOf(CacheInterface::class); - $this->object($this->testedInstance->getCacheStorageAdapter($context))->isInstanceOf($expected_adapter); + $this->assertInstanceOf(CacheInterface::class, $instance->getCacheInstance($context)); + $this->assertInstanceOf($expected_adapter, $instance->getCacheStorageAdapter($context)); if ($context === 'core') { - // test CacheManager::getCoreCacheInstance() - $this->object($this->testedInstance->getCoreCacheInstance())->isInstanceOf(CacheInterface::class); + // test CacheManager::getCoreCacheInstance() + $this->assertInstanceOf(CacheInterface::class, $instance->getCoreCacheInstance()); } } @@ -373,29 +379,34 @@ function () use ($context) { public function testGetCacheInstanceDefault(string $context, bool $is_valid, bool $is_configurable): void { if (!$is_valid) { + //phpunit is not happy when no assertions are run. + $this->assertTrue(true); return; } vfsStream::setup('glpi', null, ['config' => [], 'files' => ['_cache' => []]]); - $this->newTestedInstance(vfsStream::url('glpi/config'), vfsStream::url('glpi/files/_cache')); + $instance = new \Glpi\Cache\CacheManager( + vfsStream::url('glpi/config'), + vfsStream::url('glpi/files/_cache') + ); - $this->object($this->testedInstance->getCacheInstance($context))->isInstanceOf(CacheInterface::class); + $this->assertInstanceOf(CacheInterface::class, $instance->getCacheInstance($context)); - $this->object($this->testedInstance->getCacheStorageAdapter($context))->isInstanceOf(FilesystemAdapter::class); + $this->assertInstanceOf(FilesystemAdapter::class, $instance->getCacheStorageAdapter($context)); if ($context === 'core') { - $this->object($this->testedInstance->getCoreCacheInstance())->isInstanceOf(CacheInterface::class); + $this->assertInstanceOf(CacheInterface::class, $instance->getCoreCacheInstance()); } if ($context === 'installer') { - $this->object($this->testedInstance->getInstallerCacheInstance())->isInstanceOf(CacheInterface::class); + $this->assertInstanceOf(CacheInterface::class, $instance->getInstallerCacheInstance()); } if ($context === 'translations') { - $this->object($this->testedInstance->getTranslationsCacheInstance())->isInstanceOf(CacheInterface::class); + $this->assertInstanceOf(CacheInterface::class, $instance->getTranslationsCacheInstance()); } } - protected function dsnProvider(): iterable + public static function dsnProvider(): iterable { yield [ 'dsn' => 'memcached://user:pass@127.0.0.1:1015?weight=20', @@ -442,9 +453,12 @@ public function testIsDsnValid($dsn, bool $is_valid, ?string $scheme = null): vo vfsStream::setup('glpi', null, ['config' => [], 'files' => ['_cache' => []]]); - $this->newTestedInstance(vfsStream::url('glpi/config'), vfsStream::url('glpi/files/_cache')); + $instance = new \Glpi\Cache\CacheManager( + vfsStream::url('glpi/config'), + vfsStream::url('glpi/files/_cache') + ); - $this->boolean($this->testedInstance->isDsnValid($dsn))->isIdenticalTo($is_valid); + $this->assertSame($is_valid, $instance->isDsnValid($dsn)); } /** @@ -455,9 +469,12 @@ public function testExtractScheme($dsn, bool $is_valid, ?string $scheme = null): vfsStream::setup('glpi', null, ['config' => [], 'files' => ['_cache' => []]]); - $this->newTestedInstance(vfsStream::url('glpi/config'), vfsStream::url('glpi/files/_cache')); + $instance = new \Glpi\Cache\CacheManager( + vfsStream::url('glpi/config'), + vfsStream::url('glpi/files/_cache') + ); - $this->variable($this->testedInstance->extractScheme($dsn))->isIdenticalTo($scheme); + $this->assertSame($scheme, $instance->extractScheme($dsn)); } public function testGetKnownContexts() @@ -465,24 +482,27 @@ public function testGetKnownContexts() $vfs_structure = vfsStream::setup('glpi', null, ['config' => [], 'files' => ['_cache' => []]]); - $this->newTestedInstance(vfsStream::url('glpi/config'), vfsStream::url('glpi/files/_cache')); + $instance = new \Glpi\Cache\CacheManager( + vfsStream::url('glpi/config'), + vfsStream::url('glpi/files/_cache') + ); - // Check base contexts + // Check base contexts $expected_contexts = [ 'core', 'installer', 'translations', ]; - $this->variable($this->testedInstance->getKnownContexts())->isIdenticalTo($expected_contexts); + $this->assertSame($expected_contexts, $instance->getKnownContexts()); - // Check context extracted from config file + // Check context extracted from config file foreach (['plugin:a', 'plugin:b'] as $context) { - $this->testedInstance->setConfiguration($context, 'memcached://localhost'); + $instance->setConfiguration($context, 'memcached://localhost'); $expected_contexts[] = $context; } - $this->variable($this->testedInstance->getKnownContexts())->isIdenticalTo($expected_contexts); + $this->assertSame($expected_contexts, $instance->getKnownContexts()); - // Check contexts extracted from existing directories + // Check contexts extracted from existing directories vfsStream::create( [ 'files' => [ @@ -498,7 +518,7 @@ public function testGetKnownContexts() ); $expected_contexts[] = 'plugin:c'; $expected_contexts[] = 'plugin:d'; - $this->variable($this->testedInstance->getKnownContexts())->isIdenticalTo($expected_contexts); + $this->assertSame($expected_contexts, $instance->getKnownContexts()); } public function testSetNamespacePrefix() @@ -506,30 +526,33 @@ public function testSetNamespacePrefix() vfsStream::setup('glpi', null, ['config' => [], 'files' => ['_cache' => []]]); - $this->newTestedInstance(vfsStream::url('glpi/config'), vfsStream::url('glpi/files/_cache')); + $instance = new \Glpi\Cache\CacheManager( + vfsStream::url('glpi/config'), + vfsStream::url('glpi/files/_cache') + ); $config_file = vfsStream::url('glpi/config/' . \Glpi\Cache\CacheManager::CONFIG_FILENAME); - // Defines a non empty namespace - $this->boolean($this->testedInstance->setNamespacePrefix('my-instance'))->isTrue(); + // Defines a non empty namespace + $this->assertTrue($instance->setNamespacePrefix('my-instance')); $expected_config = [ 'namespace_prefix' => 'my-instance', 'contexts' => [], ]; - $this->boolean(file_exists($config_file))->isTrue(); - $this->array(include($config_file))->isEqualTo($expected_config); + $this->assertTrue(file_exists($config_file)); + $this->assertEquals($expected_config, include($config_file)); // Defines an empty namespace, should be saved as null - $this->boolean($this->testedInstance->setNamespacePrefix(''))->isTrue(); + $this->assertTrue($instance->setNamespacePrefix('')); $expected_config = [ 'namespace_prefix' => null, 'contexts' => [], ]; - $this->boolean(file_exists($config_file))->isTrue(); - $this->array(include($config_file))->isEqualTo($expected_config); + $this->assertTrue(file_exists($config_file)); + $this->assertEquals($expected_config, include($config_file)); } } diff --git a/tests/functional/Glpi/Cache/SimpleCache.php b/phpunit/functional/Glpi/Cache/SimpleCache.php similarity index 65% rename from tests/functional/Glpi/Cache/SimpleCache.php rename to phpunit/functional/Glpi/Cache/SimpleCache.php index 25d143dd826..fe3b3a356aa 100644 --- a/tests/functional/Glpi/Cache/SimpleCache.php +++ b/phpunit/functional/Glpi/Cache/SimpleCache.php @@ -50,7 +50,7 @@ public function testOperationsOnCache() $cache_manager = new CacheManager(); $instance = $cache_manager->getCoreCacheInstance(); - // Different scalar types to test. + // Different scalar types to test. $values = [ 'null' => null, 'string' => 'some value', @@ -65,54 +65,54 @@ public function testOperationsOnCache() '{}()/\@:' => 'reserved chars in key', ]; - // Test single set/get/has/delete + // Test single set/get/has/delete foreach ($values as $key => $value) { - // Not yet existing - $this->boolean($instance->has($key))->isFalse(); + // Not yet existing + $this->assertFalse($instance->has($key)); - // Can be set if not existing - $this->boolean($instance->set($key, $value))->isTrue(); + // Can be set if not existing + $this->assertTrue($instance->set($key, $value)); - // Is existing after being set - $this->boolean($instance->has($key))->isTrue(); + // Is existing after being set + $this->assertTrue($instance->has($key)); - // Cached value is equal to value that was set - $this->variable($instance->get($key))->isEqualTo($value); + // Cached value is equal to value that was set + $this->assertEquals($value, $instance->get($key)); - // Overwriting an existing value works + // Overwriting an existing value works $rand = mt_rand(); - $this->boolean($instance->set($key, $rand))->isTrue(); - $this->variable($instance->get($key))->isEqualTo($rand); + $this->assertTrue($instance->set($key, $rand)); + $this->assertEquals($rand, $instance->get($key)); - // Can delete a value - $this->boolean($instance->delete($key))->isTrue(); + // Can delete a value + $this->assertTrue($instance->delete($key)); } - // Test multiple set/get + // Test multiple set/get $instance->setMultiple($values); foreach ($values as $key => $value) { // Cached value exists and is equal to value that was set - $this->boolean($instance->has($key))->isTrue(); - $this->variable($instance->get($key))->isEqualTo($value); + $this->assertTrue($instance->has($key)); + $this->assertEquals($value, $instance->get($key)); } - // Test only on partial result to be sure that "*Multiple" methods acts only on targetted elements + // Test only on partial result to be sure that "*Multiple" methods acts only on targetted elements $some_keys = array_rand($values, 4); $some_values = array_intersect_key($values, array_fill_keys($some_keys, null)); - $this->array($instance->getMultiple($some_keys))->isEqualTo($some_values); + $this->assertEquals($some_values, $instance->getMultiple($some_keys)); $instance->deleteMultiple($some_keys); foreach ($some_keys as $key) { - // Cached value should not exists as it has been deleted - $this->boolean($instance->has($key))->isFalse(); + // Cached value should not exist as it has been deleted + $this->assertFalse($instance->has($key)); } // Test global clear $instance->clear(); foreach (array_keys($values) as $key) { - // Cached value should not exists as it has been deleted - $this->boolean($instance->has($key))->isFalse(); + // Cached value should not exist as it has been deleted + $this->assertFalse($instance->has($key)); } } } diff --git a/tests/functional/Glpi/Inventory/Assets/Antivirus.php b/phpunit/functional/Glpi/Inventory/Assets/Antivirus.php similarity index 73% rename from tests/functional/Glpi/Inventory/Assets/Antivirus.php rename to phpunit/functional/Glpi/Inventory/Assets/Antivirus.php index c8f0b3ec6be..82baf974baf 100644 --- a/tests/functional/Glpi/Inventory/Assets/Antivirus.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Antivirus.php @@ -41,7 +41,7 @@ class Antivirus extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -115,18 +115,15 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\Antivirus($computer, $json->content->antivirus); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testWrongMainItem() { $mainitem = getItemByTypeName('Printer', '_test_printer_all'); $asset = new \Glpi\Inventory\Asset\Antivirus($mainitem); - $this->exception( - function () use ($asset) { - $asset->prepare(); - } - )->message->contains('Antivirus are handled for computers only.'); + $this->expectExceptionMessage('Antivirus are handled for computers only.'); + $asset->prepare(); } public function testHandle() @@ -134,13 +131,15 @@ public function testHandle() global $DB; $computer = getItemByTypeName('Computer', '_test_pc01'); - //first, check there are no AV linked to this computer + //first, check there are no AV linked to this computer $avc = new \ComputerAntivirus(); - $this->boolean($avc->getFromDbByCrit(['computers_id' => $computer->fields['id']])) - ->isFalse('An antivirus is already linked to computer!'); + $this->assertFalse( + $avc->getFromDbByCrit(['computers_id' => $computer->fields['id']]), + 'An antivirus is already linked to computer!' + ); - //convert data - $expected = $this->assetProvider()[0]; + //convert data + $expected = $this::assetProvider()[0]; $converter = new \Glpi\Inventory\Converter(); $data = $converter->convert($expected['xml']); @@ -150,20 +149,22 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Antivirus($computer, $json->content->antivirus); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); - //handle + //handle $asset->handleLinks(); $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Microsoft Corporation']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $asset->handle(); - $this->boolean($avc->getFromDbByCrit(['computers_id' => $computer->fields['id']])) - ->isTrue('Antivirus has not been linked to computer :('); + $this->assertTrue( + $avc->getFromDbByCrit(['computers_id' => $computer->fields['id']]), + 'Antivirus has not been linked to computer :(' + ); - $this->integer($avc->fields['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertSame($manufacturers_id, $avc->fields['manufacturers_id']); } public function testUpdate() @@ -174,13 +175,15 @@ public function testUpdate() //first, check there are no AV linked to this computer $avc = new \ComputerAntivirus(); - $this->boolean($avc->getFromDbByCrit(['computers_id' => $computer->fields['id']])) - ->isTrue('No antivirus linked to computer!'); + $this->assertTrue( + $avc->getFromDbByCrit(['computers_id' => $computer->fields['id']]), + 'No antivirus linked to computer!' + ); - $expected = $this->assetProvider()[0]; + $expected = $this::assetProvider()[0]; $json_expected = json_decode($expected['expected']); $xml = $expected['xml']; - //change version + //change version $xml = str_replace('4.3.216.0', '4.5.12.0', $xml); $json_expected->version = '4.5.12.0'; $json_expected->antivirus_version = '4.5.12.0'; @@ -192,13 +195,13 @@ public function testUpdate() $asset = new \Glpi\Inventory\Asset\Antivirus($computer, $json->content->antivirus); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo($json_expected); + $this->assertEquals($json_expected, $result[0]); $asset->handleLinks(); $asset->handle(); - $this->boolean($avc->getFromDbByCrit(['computers_id' => $computer->fields['id']]))->isTrue(); + $this->assertTrue($avc->getFromDbByCrit(['computers_id' => $computer->fields['id']])); - $this->string($avc->fields['antivirus_version'])->isIdenticalTo('4.5.12.0'); + $this->assertSame('4.5.12.0', $avc->fields['antivirus_version']); } public function testInventoryUpdate() @@ -238,13 +241,13 @@ public function testInventoryUpdate() INVENTORY "; - //create manually a computer, with 3 antivirus + //create manually a computer, with 3 antivirus $computers_id = $computer->add([ 'name' => 'pc002', 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $antivirus_1_id = $antivirus->add([ 'computers_id' => $computers_id, @@ -252,7 +255,7 @@ public function testInventoryUpdate() 'antivirus_version' => '2021 21.3.10.391', 'is_active' => 1 ]); - $this->integer($antivirus_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $antivirus_1_id); $antivirus_2_id = $antivirus->add([ 'computers_id' => $computers_id, @@ -260,7 +263,7 @@ public function testInventoryUpdate() 'antivirus_version' => '4.3.216.0', 'is_active' => 1 ]); - $this->integer($antivirus_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $antivirus_2_id); $antivirus_3_id = $antivirus->add([ 'computers_id' => $computers_id, @@ -268,39 +271,39 @@ public function testInventoryUpdate() 'antivirus_version' => '19', 'is_active' => 1 ]); - $this->integer($antivirus_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $antivirus_3_id); $results = $antivirus->find(['computers_id' => $computers_id]); - $this->integer(count($results))->isIdenticalTo(3); + $this->assertCount(3, $results); foreach ($results as $result) { - $this->variable($result['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $result['is_dynamic']); } - //computer inventory knows only 2 antivirus: Microsoft and Kaspersky + //computer inventory knows only 2 antivirus: Microsoft and Kaspersky $this->doInventory($xml_source, true); - //we still have 3 antivirus linked to the computer + //we still have 3 antivirus linked to the computer $results = $antivirus->find(['computers_id' => $computers_id]); - $this->integer(count($results))->isIdenticalTo(3); + $this->assertCount(3, $results); - //antivirus present in the inventory source are now dynamic + //antivirus present in the inventory source are now dynamic $results = $antivirus->find(['computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($results))->isIdenticalTo(2); + $this->assertCount(2, $results); - $this->boolean($antivirus->getFromDB($antivirus_1_id))->isTrue(); - $this->integer($antivirus->fields['is_dynamic'])->isIdenticalTo(1); + $this->assertTrue($antivirus->getFromDB($antivirus_1_id)); + $this->assertSame(1, $antivirus->fields['is_dynamic']); - $this->boolean($antivirus->getFromDB($antivirus_2_id))->isTrue(); - $this->integer($antivirus->fields['is_dynamic'])->isIdenticalTo(1); + $this->assertTrue($antivirus->getFromDB($antivirus_2_id)); + $this->assertSame(1, $antivirus->fields['is_dynamic']); - //antivirus not present in the inventory is still not dynamic + //antivirus not present in the inventory is still not dynamic $results = $antivirus->find(['computers_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($results))->isIdenticalTo(1); + $this->assertCount(1, $results); - $this->boolean($antivirus->getFromDB($antivirus_3_id))->isTrue(); - $this->integer($antivirus->fields['is_dynamic'])->isIdenticalTo(0); + $this->assertTrue($antivirus->getFromDB($antivirus_3_id)); + $this->assertSame(0, $antivirus->fields['is_dynamic']); - //Redo inventory, but with removed microsoft antivirus + //Redo inventory, but with removed microsoft antivirus $xml_source = " @@ -327,25 +330,25 @@ public function testInventoryUpdate() $this->doInventory($xml_source, true); - //we now have 2 antivirus only + //we now have 2 antivirus only $results = $antivirus->find(['computers_id' => $computers_id]); - $this->integer(count($results))->isIdenticalTo(2); + $this->assertCount(2, $results); - //antivirus present in the inventory source are still dynamic + //antivirus present in the inventory source are still dynamic $results = $antivirus->find(['computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($results))->isIdenticalTo(1); + $this->assertCount(1, $results); - $this->boolean($antivirus->getFromDB($antivirus_1_id))->isTrue(); - $this->integer($antivirus->fields['is_dynamic'])->isIdenticalTo(1); + $this->assertTrue($antivirus->getFromDB($antivirus_1_id)); + $this->assertSame(1, $antivirus->fields['is_dynamic']); - //microsoft has been removed - $this->boolean($antivirus->getFromDB($antivirus_2_id))->isFalse(); + //microsoft has been removed + $this->assertFalse($antivirus->getFromDB($antivirus_2_id)); - //antivirus not present in the inventory is still not dynamic + //antivirus not present in the inventory is still not dynamic $results = $antivirus->find(['computers_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($results))->isIdenticalTo(1); + $this->assertCount(1, $results); - $this->boolean($antivirus->getFromDB($antivirus_3_id))->isTrue(); - $this->integer($antivirus->fields['is_dynamic'])->isIdenticalTo(0); + $this->assertTrue($antivirus->getFromDB($antivirus_3_id)); + $this->assertSame(0, $antivirus->fields['is_dynamic']); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Battery.php b/phpunit/functional/Glpi/Inventory/Assets/Battery.php similarity index 79% rename from tests/functional/Glpi/Inventory/Assets/Battery.php rename to phpunit/functional/Glpi/Inventory/Assets/Battery.php index 9d527a7f283..91c31533c0b 100644 --- a/tests/functional/Glpi/Inventory/Assets/Battery.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Battery.php @@ -41,7 +41,7 @@ class Battery extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -115,19 +115,21 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\Battery($computer, $json->content->batteries); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() { $computer = getItemByTypeName('Computer', '_test_pc01'); - //first, check there are no battery linked to this computer + //first, check there are no battery linked to this computer $idb = new \Item_DeviceBattery(); - $this->boolean($idb->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A battery is already linked to computer!'); + $this->assertFalse( + $idb->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A battery is already linked to computer!' + ); - //convert data + //convert data $expected = $this->assetProvider()[0]; $converter = new \Glpi\Inventory\Converter(); @@ -138,25 +140,29 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Battery($computer, $json->content->batteries); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); - //handle + //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($idb->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Battery has not been linked to computer :('); + $this->assertTrue( + $idb->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Battery has not been linked to computer :(' + ); } public function testHandleNoFullInfo() { $computer = getItemByTypeName('Computer', '_test_pc02'); - //first, check there are no battery linked to this computer + //first, check there are no battery linked to this computer $idb = new \Item_DeviceBattery(); - $this->boolean($idb->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A battery is already linked to computer!'); + $this->assertFalse( + $idb->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A battery is already linked to computer!' + ); - //convert data + //convert data $expected = $this->assetProvider()[2]; $converter = new \Glpi\Inventory\Converter(); @@ -167,13 +173,15 @@ public function testHandleNoFullInfo() $asset = new \Glpi\Inventory\Asset\Battery($computer, $json->content->batteries); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); - //handle + //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($idb->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Battery has not been linked to computer :('); + $this->assertTrue( + $idb->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Battery has not been linked to computer :(' + ); } public function testInventoryUpdate() @@ -221,19 +229,19 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $manufacturer = new \Manufacturer(); $manufacturers_id = $manufacturer->add([ 'name' => 'SMP' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $batterytype = new \DeviceBatteryType(); $types_id = $batterytype->add([ 'name' => 'lithium-polymer' ]); - $this->integer($types_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $types_id); $battery_1_id = $device_battery->add([ 'designation' => 'DELL JHXPY53', @@ -243,7 +251,7 @@ public function testInventoryUpdate() 'capacity' => 43746, 'entities_id' => 0, ]); - $this->integer($battery_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $battery_1_id); $item_battery_1_id = $item_battery->add([ 'items_id' => $computers_id, @@ -260,7 +268,7 @@ public function testInventoryUpdate() 'capacity' => 45280, 'entities_id' => 0, ]); - $this->integer($battery_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $battery_2_id); $item_battery_2_id = $item_battery->add([ 'items_id' => $computers_id, @@ -275,41 +283,41 @@ public function testInventoryUpdate() 'devicebatterytypes_id' => $types_id, 'entities_id' => 0 ]); - $this->integer($battery_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $battery_3_id); $item_battery_3_id = $item_battery->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicebatteries_id' => $battery_3_id ]); - $this->integer($item_battery_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_battery_3_id); $disks = $item_battery->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($disks))->isIdenticalTo(3); + $this->assertCount(3, $disks); foreach ($disks as $disk) { - $this->variable($disk['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $disk['is_dynamic']); } - //computer inventory knows only "DELL JHXPY53" and "5B10W138" batteries + //computer inventory knows only "DELL JHXPY53" and "5B10W138" batteries $this->doInventory($xml_source, true); - //we still have 3 batteries + //we still have 3 batteries $batteries = $device_battery->find(); - $this->integer(count($batteries))->isIdenticalTo(3); + $this->assertCount(3, $batteries); - //we still have 3 batteries items linked to the computer + //we still have 3 batteries items linked to the computer $batteries = $item_battery->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($batteries))->isIdenticalTo(3); + $this->assertCount(3, $batteries); - //batteries present in the inventory source are now dynamic + //batteries present in the inventory source are now dynamic $batteries = $item_battery->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($batteries))->isIdenticalTo(2); + $this->assertCount(2, $batteries); - //disk not present in the inventory is still not dynamic + //disk not present in the inventory is still not dynamic $batteries = $item_battery->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($batteries))->isIdenticalTo(1); + $this->assertCount(1, $batteries); - //Redo inventory, but with removed battery "5B10W138" + //Redo inventory, but with removed battery "5B10W138" $xml_source = " @@ -336,20 +344,20 @@ public function testInventoryUpdate() $this->doInventory($xml_source, true); - //we still have 3 batteries + //we still have 3 batteries $batteries = $device_battery->find(); - $this->integer(count($batteries))->isIdenticalTo(3); + $this->assertCount(3, $batteries); - //we now have 2 batteries linked to computer only + //we now have 2 batteries linked to computer only $batteries = $item_battery->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($batteries))->isIdenticalTo(2); + $this->assertCount(2, $batteries); - //battery present in the inventory source is still dynamic + //battery present in the inventory source is still dynamic $batteries = $item_battery->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($batteries))->isIdenticalTo(1); + $this->assertCount(1, $batteries); - //battery not present in the inventory is still not dynamic + //battery not present in the inventory is still not dynamic $batteries = $item_battery->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($batteries))->isIdenticalTo(1); + $this->assertCount(1, $batteries); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Bios.php b/phpunit/functional/Glpi/Inventory/Assets/Bios.php similarity index 89% rename from tests/functional/Glpi/Inventory/Assets/Bios.php rename to phpunit/functional/Glpi/Inventory/Assets/Bios.php index d5b5a1c1eef..7d4ac27e91b 100644 --- a/tests/functional/Glpi/Inventory/Assets/Bios.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Bios.php @@ -41,7 +41,7 @@ class Bios extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -99,7 +99,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\Bios($computer, (array)$json->content->bios); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -108,8 +108,10 @@ public function testHandle() //first, check there are no controller linked to this computer $idf = new \Item_DeviceFirmware(); - $this->boolean($idf->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A firmware is already linked to computer!'); + $this->assertFalse( + $idf->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A firmware is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -122,13 +124,15 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Bios($computer, (array)$json->content->bios); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($idf->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Firmware has not been linked to computer :('); + $this->assertTrue( + $idf->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Firmware has not been linked to computer :(' + ); } public function testInventoryUpdate() @@ -170,7 +174,7 @@ public function testInventoryUpdate() $manufacturers_id = $manufacturer->add([ 'name' => 'Dell Inc.' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); //create manually a computer, with a bios $computers_id = $computer->add([ @@ -178,7 +182,7 @@ public function testInventoryUpdate() 'serial' => addslashes("ggheb7'ne7"), 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $bios_id = $device_bios->add([ 'designation' => 'Dell Inc. BIOS', @@ -192,12 +196,12 @@ public function testInventoryUpdate() 'itemtype' => 'Computer', 'devicefirmwares_id' => $bios_id ]); - $this->integer($item_bios_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_bios_id); $firmwares = $item_bios->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($firmwares))->isIdenticalTo(1); + $this->assertCount(1, $firmwares); foreach ($firmwares as $firmware) { - $this->variable($firmware['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $firmware['is_dynamic']); } //computer inventory knows bios @@ -205,11 +209,11 @@ public function testInventoryUpdate() //we still have 1 bios linked to the computer $firmwares = $item_bios->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($firmwares))->isIdenticalTo(1); + $this->assertCount(1, $firmwares); //bios present in the inventory source is now dynamic $firmwares = $item_bios->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($firmwares))->isIdenticalTo(1); + $this->assertCount(1, $firmwares); //Redo inventory, but with modified firmware => will create a new one $xml_source = " @@ -239,14 +243,14 @@ public function testInventoryUpdate() //we still have one firmware $firmwares = $item_bios->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($firmwares))->isIdenticalTo(1); + $this->assertCount(1, $firmwares); //bios present in the inventory source is still dynamic $firmwares = $item_bios->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($firmwares))->isIdenticalTo(1); + $this->assertCount(1, $firmwares); //"original" firmware has been removed - $this->boolean($item_bios->getFromDB($item_bios_id))->isFalse(); + $this->assertFalse($item_bios->getFromDB($item_bios_id)); } public function testHistory() @@ -296,11 +300,11 @@ public function testHistory() $networkequipement = new \NetworkEquipment(); $networkequipement->getFromDBByCrit(['name' => 'TECLIB678']); - $this->integer($networkequipement->getID())->isGreaterThan(0); + $this->assertGreaterThan(0, $networkequipement->getID()); //bios present in the inventory source is dynamic $firmwares = $item_bios->find(['itemtype' => \NetworkEquipment::class, 'items_id' => $networkequipement->getID(), 'is_dynamic' => 1]); - $this->integer(count($firmwares))->isIdenticalTo(1); + $this->assertCount(1, $firmwares); //no log from first import (Computer or Monitor) $nblogsnow = countElementsInTable(\Log::getTable()); @@ -314,7 +318,7 @@ public function testHistory() 'itemtype_link' => \DeviceFirmware::class ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); // change version // As the version is one of the reconciliation keys, we should see a deletion and then an addition. @@ -359,11 +363,11 @@ public function testHistory() $networkequipement = new \NetworkEquipment(); $networkequipement->getFromDBByCrit(['name' => 'TECLIB678']); - $this->integer($networkequipement->getID())->isGreaterThan(0); + $this->assertGreaterThan(0, $networkequipement->getID()); //bios present in the inventory source is dynamic $firmwares = $item_bios->find(['itemtype' => \NetworkEquipment::class, 'items_id' => $networkequipement->getID(), 'is_dynamic' => 1]); - $this->integer(count($firmwares))->isIdenticalTo(1); + $this->assertCount(1, $firmwares); //one log for delete old firmware $logs = $DB->request([ @@ -376,7 +380,7 @@ public function testHistory() ] ]); - $this->integer(count($logs))->isIdenticalTo(1); + $this->assertCount(1, $logs); //one log for add new firmware $logs = $DB->request([ @@ -389,6 +393,6 @@ public function testHistory() ] ]); - $this->integer(count($logs))->isIdenticalTo(1); + $this->assertCount(1, $logs); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Camera.php b/phpunit/functional/Glpi/Inventory/Assets/Camera.php similarity index 84% rename from tests/functional/Glpi/Inventory/Assets/Camera.php rename to phpunit/functional/Glpi/Inventory/Assets/Camera.php index ebe88830cd7..eba8b24fc01 100644 --- a/tests/functional/Glpi/Inventory/Assets/Camera.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Camera.php @@ -41,7 +41,7 @@ class Camera extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -91,7 +91,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\Camera($computer, $json->content->cameras); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -100,8 +100,10 @@ public function testHandle() //first, check there are no camera linked to this computer $idc = new \Item_DeviceCamera(); - $this->boolean($idc->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A camera is already linked to computer!'); + $this->assertFalse( + $idc->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A camera is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -114,31 +116,33 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Camera($computer, $json->content->cameras); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($idc->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Camera has not been linked to computer :('); + $this->assertTrue( + $idc->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Camera has not been linked to computer :(' + ); global $DB; //four resolutions has been created $iterator = $DB->request(['FROM' => \ImageResolution::getTable()]); - $this->integer(count($iterator))->isIdenticalTo(4); + $this->assertCount(4, $iterator); //four images formats has been created $iterator = $DB->request(['FROM' => \ImageFormat::getTable()]); - $this->integer(count($iterator))->isIdenticalTo(4); + $this->assertCount(4, $iterator); //four links between images formats and camera has been created $iterator = $DB->request(['FROM' => \Item_DeviceCamera_ImageFormat::getTable()]); - $this->integer(count($iterator))->isIdenticalTo(4); + $this->assertCount(4, $iterator); //four links between images resolutions and camera has been created $iterator = $DB->request(['FROM' => \Item_DeviceCamera_ImageResolution::getTable()]); - $this->integer(count($iterator))->isIdenticalTo(4); + $this->assertCount(4, $iterator); } public function testInventoryUpdate() @@ -178,19 +182,19 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $manufacturer = new \Manufacturer(); $manufacturers_id = $manufacturer->add([ 'name' => 'Xiaomi' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $model = new \DeviceCameraModel(); $models_id = $model->add([ 'name' => 'test' ]); - $this->integer($models_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $models_id); $cam_1_id = $device_cam->add([ 'designation' => 'Front cam', @@ -198,7 +202,7 @@ public function testInventoryUpdate() 'devicecameramodels_id' => $models_id, 'entities_id' => 0 ]); - $this->integer($cam_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $cam_1_id); $item_cam_1_id = $item_cam->add([ 'items_id' => $computers_id, @@ -212,7 +216,7 @@ public function testInventoryUpdate() 'devicecameramodels_id' => $models_id, 'entities_id' => 0 ]); - $this->integer($cam_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $cam_2_id); $item_cam_2_id = $item_cam->add([ 'items_id' => $computers_id, @@ -226,7 +230,7 @@ public function testInventoryUpdate() 'devicecameramodels_id' => $models_id, 'entities_id' => 0 ]); - $this->integer($cam_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $cam_3_id); $item_cam_3_id = $item_cam->add([ 'items_id' => $computers_id, @@ -235,9 +239,9 @@ public function testInventoryUpdate() ]); $cams = $item_cam->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($cams))->isIdenticalTo(3); + $this->assertCount(3, $cams); foreach ($cams as $cam) { - $this->variable($cam['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $cam['is_dynamic']); } //computer inventory knows only "Front" and "Rear" cameras @@ -245,19 +249,19 @@ public function testInventoryUpdate() //we still have 3 cameras $cams = $device_cam->find(); - $this->integer(count($cams))->isIdenticalTo(3); + $this->assertCount(3, $cams); //we still have 3 cameras items linked to the computer $cams = $item_cam->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($cams))->isIdenticalTo(3); + $this->assertCount(3, $cams); //cameras present in the inventory source are now dynamic $cams = $item_cam->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($cams))->isIdenticalTo(2); + $this->assertCount(2, $cams); //camera not present in the inventory is still not dynamic $cams = $item_cam->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($cams))->isIdenticalTo(1); + $this->assertCount(1, $cams); //Redo inventory, but with removed "Rear" camera $xml_source = " @@ -284,18 +288,18 @@ public function testInventoryUpdate() //we still have 3 cameras $cams = $device_cam->find(); - $this->integer(count($cams))->isIdenticalTo(3); + $this->assertCount(3, $cams); //we now have 2 cameras linked to computer only $cams = $item_cam->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($cams))->isIdenticalTo(2); + $this->assertCount(2, $cams); //camera present in the inventory source is still dynamic $cams = $item_cam->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($cams))->isIdenticalTo(1); + $this->assertCount(1, $cams); //camera not present in the inventory is still not dynamic $cams = $item_cam->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($cams))->isIdenticalTo(1); + $this->assertCount(1, $cams); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Cartridge.php b/phpunit/functional/Glpi/Inventory/Assets/Cartridge.php similarity index 85% rename from tests/functional/Glpi/Inventory/Assets/Cartridge.php rename to phpunit/functional/Glpi/Inventory/Assets/Cartridge.php index 340ecef2999..f83765c4977 100644 --- a/tests/functional/Glpi/Inventory/Assets/Cartridge.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Cartridge.php @@ -41,7 +41,7 @@ class Cartridge extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -97,7 +97,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\Cartridge($printer, $json->content->cartridges); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testKnownTags() @@ -105,9 +105,9 @@ public function testKnownTags() $cart = new \Glpi\Inventory\Asset\Cartridge(getItemByTypeName('Printer', '_test_printer_all')); $tags = $cart->knownTags(); - $this->array($tags)->hasSize(194); + $this->assertCount(194, $tags); foreach ($tags as $tag) { - $this->array($tag)->hasKey('name'); + $this->assertArrayHasKey('name', $tag); } } @@ -124,7 +124,7 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Cartridge($printer, $json->content->cartridges); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode('{"tonerblack":"71"}')); + $this->assertEquals(json_decode('{"tonerblack":"71"}'), $result[0]); $agent = new \Agent(); $agent->getEmpty(); @@ -141,12 +141,12 @@ public function testHandle() 'FROM' => \Printer_CartridgeInfo::getTable(), 'WHERE' => ['printers_id' => $printers_id] ]); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); $result = $iterator->current(); - $this->array($result) - ->string['property']->isIdenticalTo('tonerblack') - ->string['value']->isIdenticalTo('71'); + $this->assertIsArray($result); + $this->assertSame('tonerblack', $result['property']); + $this->assertSame('71', $result['value']); //test level changed $json = json_decode($data); @@ -155,7 +155,7 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Cartridge($printer, $json->content->cartridges); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode('{"tonerblack":"60"}')); + $this->assertEquals(json_decode('{"tonerblack":"60"}'), $result[0]); //handle $asset->handleLinks(); @@ -166,20 +166,20 @@ public function testHandle() 'FROM' => \Printer_CartridgeInfo::getTable(), 'WHERE' => ['printers_id' => $printers_id] ]); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); $result = $iterator->current(); - $this->array($result) - ->string['property']->isIdenticalTo('tonerblack') - ->string['value']->isIdenticalTo('60'); + $this->assertIsArray($result); + $this->assertSame('tonerblack', $result['property']); + $this->assertSame('60', $result['value']); //test Printer_CartridgeInfo removal - $this->boolean($printer->delete(['id' => $printers_id], true))->isTrue(); + $this->assertTrue($printer->delete(['id' => $printers_id], true)); $iterator = $DB->request([ 'FROM' => \Printer_CartridgeInfo::getTable(), 'WHERE' => ['printers_id' => $printers_id] ]); - $this->integer(count($iterator))->isIdenticalTo(0); + $this->assertCount(0, $iterator); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Computer.php b/phpunit/functional/Glpi/Inventory/Assets/ComputerTest.php similarity index 71% rename from tests/functional/Glpi/Inventory/Assets/Computer.php rename to phpunit/functional/Glpi/Inventory/Assets/ComputerTest.php index 8c5f917e0e4..39705e5e397 100644 --- a/tests/functional/Glpi/Inventory/Assets/Computer.php +++ b/phpunit/functional/Glpi/Inventory/Assets/ComputerTest.php @@ -39,11 +39,11 @@ /* Test for inc/inventory/asset/computer.class.php */ -class Computer extends AbstractInventoryAsset +class ComputerTest extends AbstractInventoryAsset { const INV_FIXTURES = GLPI_ROOT . '/vendor/glpi-project/inventory_format/examples/'; - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ //both bios and hardware @@ -189,7 +189,7 @@ public function testPrepare($xml, $asset) $main = new \Glpi\Inventory\Asset\Computer($computer, $json); $main->setExtraData((array)$json->content); $result = $main->prepare(); - $this->object($result[0])->isEqualTo(json_decode($asset)); + $this->assertEquals(json_decode($asset), $result[0]); } public function testAutoCleanWithoutLockedField() @@ -202,7 +202,7 @@ public function testAutoCleanWithoutLockedField() "name" => "manual monitor", "entities_id" => 0 ]); - $this->integer($manual_monitor_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manual_monitor_id); $CFG_GLPI['is_user_autoupdate'] = 1; @@ -248,85 +248,86 @@ public function testAutoCleanWithoutLockedField() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps.teclib.infra-2018-10-03-08-42-36') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps.teclib.infra-2018-10-03-08-42-36', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); - $this->integer($computer->fields['users_id'])->isIdenticalTo(getItemByTypeName('User', 'tech', true)); + $this->assertTrue($computer->getFromDB($computers_id)); + $this->assertSame(getItemByTypeName('User', 'tech', true), $computer->fields['users_id']); //add manual manual monitor to computer - $this->integer($item_monitor->add([ - "itemtype" => "Monitor", - "items_id" => $manual_monitor_id, - "computers_id" => $computers_id - ]))->isGreaterThan(0); + $this->assertGreaterThan( + 0, + $item_monitor->add([ + "itemtype" => "Monitor", + "items_id" => $manual_monitor_id, + "computers_id" => $computers_id + ]) + ); - $this->integer($computer->fields['users_id'])->isGreaterThan(0); + $this->assertGreaterThan(0, $computer->fields['users_id']); //one dynamic monitor linked $dynamic_monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($dynamic_monitors))->isIdenticalTo(1); + $this->assertCount(1, $dynamic_monitors); //one manual monitor linked $manual_monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($manual_monitors))->isIdenticalTo(1); + $this->assertCount(1, $manual_monitors); //load dynamic monitor $dynamic_monitor = new \Monitor(); - $this->boolean($dynamic_monitor->getFromDB(reset($dynamic_monitors)['items_id']))->isTrue(); + $this->assertTrue($dynamic_monitor->getFromDB(reset($dynamic_monitors)['items_id'])); //check same users - $this->integer($dynamic_monitor->fields['users_id'])->isIdenticalTo($computer->fields['users_id']); - $this->integer($dynamic_monitor->fields['users_id'])->isIdenticalTo(getItemByTypeName('User', 'tech', true)); + $this->assertSame($computer->fields['users_id'], $dynamic_monitor->fields['users_id']); + $this->assertSame(getItemByTypeName('User', 'tech', true), $dynamic_monitor->fields['users_id']); //load manual monitor $manual_monitor = new \Monitor(); - $this->boolean($manual_monitor->getFromDB(reset($manual_monitors)['items_id']))->isTrue(); + $this->assertTrue($manual_monitor->getFromDB(reset($manual_monitors)['items_id'])); //check same users - $this->integer($manual_monitor->fields['users_id'])->isIdenticalTo($computer->fields['users_id']); - $this->integer($manual_monitor->fields['users_id'])->isIdenticalTo(getItemByTypeName('User', 'tech', true)); - + $this->assertSame($computer->fields['users_id'], $manual_monitor->fields['users_id']); + $this->assertSame(getItemByTypeName('User', 'tech', true), $manual_monitor->fields['users_id']); //Enable option to clean users_id when element is disconnected $CFG_GLPI['is_user_autoclean'] = 1; - //remove Computer_Item for dynamic monitor $item_dynamic_monitor_id = reset($dynamic_monitors)['id']; - $this->boolean($item_monitor->getFromDB($item_dynamic_monitor_id))->isTrue(); - $this->boolean($item_monitor->delete($item_monitor->fields, 1))->isTrue(); + $this->assertTrue($item_monitor->getFromDB($item_dynamic_monitor_id)); + $this->assertTrue($item_monitor->delete($item_monitor->fields, 1)); // reload dynamic monitor and check users_id - $this->boolean($dynamic_monitor->getFromDB($dynamic_monitor->getID()))->isTrue(); - $this->integer($dynamic_monitor->fields['users_id'])->isIdenticalTo(0); + $this->assertTrue($dynamic_monitor->getFromDB($dynamic_monitor->getID())); + $this->assertSame(0, $dynamic_monitor->fields['users_id']); //remove Computer_Item for manual monitor $item_manual_monitor_id = reset($manual_monitors)['id']; - $this->boolean($item_monitor->getFromDB($item_manual_monitor_id))->isTrue(); - $this->boolean($item_monitor->delete($item_monitor->fields, 1))->isTrue(); + $this->assertTrue($item_monitor->getFromDB($item_manual_monitor_id)); + $this->assertTrue($item_monitor->delete($item_monitor->fields, 1)); //reload manual monitor and check users_id - $this->boolean($manual_monitor->getFromDB($manual_monitor->getID()))->isTrue(); - $this->integer($manual_monitor->fields['users_id'])->isIdenticalTo(0); + $this->assertTrue($manual_monitor->getFromDB($manual_monitor->getID())); + $this->assertSame(0, $manual_monitor->fields['users_id']); $locked_field = new \Lockedfield(); //no lock from computer $locks = $locked_field->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($locks))->isIdenticalTo(0); + $this->assertCount(0, $locks); //no lock from dynamic monitor $locks = $locked_field->find(['itemtype' => 'Monitor', 'items_id' => $dynamic_monitor->getID()]); - $this->integer(count($locks))->isIdenticalTo(0); + $this->assertCount(0, $locks); //no lock from manual monitor $locks = $locked_field->find(['itemtype' => 'Monitor', 'items_id' => $manual_monitor->getID()]); - $this->integer(count($locks))->isIdenticalTo(0); + $this->assertCount(0, $locks); } public function testAutoUpdateWithoutLockedField() @@ -339,7 +340,7 @@ public function testAutoUpdateWithoutLockedField() "name" => "manual monitor", "entities_id" => 0 ]); - $this->integer($manual_monitor_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manual_monitor_id); $xml = " @@ -383,47 +384,50 @@ public function testAutoUpdateWithoutLockedField() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps.teclib.infra-2018-10-03-08-42-36') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps.teclib.infra-2018-10-03-08-42-36', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //add manual manual monitor to computer - $this->integer($item_monitor->add([ - "itemtype" => "Monitor", - "items_id" => $manual_monitor_id, - "computers_id" => $computers_id - ]))->isGreaterThan(0); + $this->assertGreaterThan( + 0, + $item_monitor->add([ + "itemtype" => "Monitor", + "items_id" => $manual_monitor_id, + "computers_id" => $computers_id + ]) + ); - $this->integer($computer->fields['users_id'])->isGreaterThan(0); + $this->assertGreaterThan(0, $computer->fields['users_id']); //one dynamic monitor linked $dynamic_monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($dynamic_monitors))->isIdenticalTo(1); + $this->assertCount(1, $dynamic_monitors); //one manual monitor linked $manual_monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($manual_monitors))->isIdenticalTo(1); + $this->assertCount(1, $manual_monitors); //load dynamic monitor $dynamic_monitor = new \Monitor(); - $this->boolean($dynamic_monitor->getFromDB(reset($dynamic_monitors)['items_id']))->isTrue(); + $this->assertTrue($dynamic_monitor->getFromDB(reset($dynamic_monitors)['items_id'])); //check same users - $this->integer($dynamic_monitor->fields['users_id'])->isIdenticalTo($computer->fields['users_id']); + $this->assertSame($computer->fields['users_id'], $dynamic_monitor->fields['users_id']); //load manual monitor $manual_monitor = new \Monitor(); - $this->boolean($manual_monitor->getFromDB(reset($manual_monitors)['items_id']))->isTrue(); + $this->assertTrue($manual_monitor->getFromDB(reset($manual_monitors)['items_id'])); //check same users - $this->integer($manual_monitor->fields['users_id'])->isIdenticalTo($computer->fields['users_id']); + $this->assertSame($computer->fields['users_id'], $manual_monitor->fields['users_id']); //Enable option to propagate users_id on update to connected element $CFG_GLPI['is_user_autoupdate'] = 1; @@ -471,56 +475,56 @@ public function testAutoUpdateWithoutLockedField() //check agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps.teclib.infra-2018-10-03-08-42-36') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps.teclib.infra-2018-10-03-08-42-36', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); - $this->integer($computer->fields['users_id'])->isGreaterThan(0); + $this->assertGreaterThan(0, $computer->fields['users_id']); //one dynamic monitor linked $dynamic_monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($dynamic_monitors))->isIdenticalTo(1); + $this->assertCount(1, $dynamic_monitors); //one manual monitor linked $monitors_manual = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($monitors_manual))->isIdenticalTo(1); + $this->assertCount(1, $monitors_manual); //load dynamic monitor $dynamic_monitor = new \Monitor(); $dynamic_monitor_id = reset($dynamic_monitors)['items_id']; - $this->boolean($dynamic_monitor->getFromDB($dynamic_monitor_id))->isTrue(); + $this->assertTrue($dynamic_monitor->getFromDB($dynamic_monitor_id)); //check same users - $this->integer($dynamic_monitor->fields['users_id'])->isIdenticalTo($computer->fields['users_id']); + $this->assertSame($computer->fields['users_id'], $dynamic_monitor->fields['users_id']); //load manual monitor $manual_monitor = new \Monitor(); $manual_monitor_id = reset($monitors_manual)['items_id']; - $this->boolean($manual_monitor->getFromDB($manual_monitor_id))->isTrue(); + $this->assertTrue($manual_monitor->getFromDB($manual_monitor_id)); //check same users - $this->integer($manual_monitor->fields['users_id'])->isIdenticalTo($computer->fields['users_id']); + $this->assertSame($computer->fields['users_id'], $manual_monitor->fields['users_id']); $locked_field = new \Lockedfield(); //no lock from computer $locks = $locked_field->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($locks))->isIdenticalTo(0); + $this->assertCount(0, $locks); //no lock from dynamic monitor $locks = $locked_field->find(['itemtype' => 'Monitor', 'items_id' => $dynamic_monitor_id]); - $this->integer(count($locks))->isIdenticalTo(0); + $this->assertCount(0, $locks); //no lock from manual monitor $locks = $locked_field->find(['itemtype' => 'Monitor', 'items_id' => $manual_monitor_id]); - $this->integer(count($locks))->isIdenticalTo(0); + $this->assertCount(0, $locks); } public function testHandle() @@ -532,18 +536,18 @@ public function testHandle() $data = (array)$json->content; $inventory = new \Glpi\Inventory\Inventory(); - $this->boolean($inventory->setData($json))->isTrue(); + $this->assertTrue($inventory->setData($json)); $agent = new \Agent(); - $this->integer($agent->handleAgent($inventory->extractMetadata()))->isGreaterThan(0); + $this->assertGreaterThan(0, $agent->handleAgent($inventory->extractMetadata())); $main = new \Glpi\Inventory\Asset\Computer($computer, $json); $main->setAgent($agent)->setExtraData($data); $result = $main->prepare(); - $this->array($result)->hasSize(1); + $this->assertCount(1, $result); $main->handle(); - $this->boolean($main->areLinksHandled())->isTrue(); + $this->assertTrue($main->areLinksHandled()); } public function testHandleMserial() @@ -587,46 +591,46 @@ public function testHandleMserial() 'WHERE' => [] ]; $iterator = $DB->request($criteria); - $this->string($iterator->current()['name'])->isIdenticalTo('Computer import (by serial + uuid)'); + $this->assertSame('Computer import (by serial + uuid)', $iterator->current()['name']); //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps.teclib.infra-2018-10-03-08-42-36') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps.teclib.infra-2018-10-03-08-42-36', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check serial came from "MSN" node. - $this->string($computer->fields['serial'])->isIdenticalTo('640HP72'); + $this->assertSame('640HP72', $computer->fields['serial']); //Reimport, should not create a new computer $this->doInventory($json); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps.teclib.infra-2018-10-03-08-42-36') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps.teclib.infra-2018-10-03-08-42-36', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer - the same as before - $this->integer($agent['items_id'])->isIdenticalTo($computers_id); + $this->assertSame($computers_id, $agent['items_id']); $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check serial came from "MSN" node. - $this->string($computer->fields['serial'])->isIdenticalTo('640HP72'); + $this->assertSame('640HP72', $computer->fields['serial']); } public function testHandleMserialOnly() @@ -669,46 +673,46 @@ public function testHandleMserialOnly() 'WHERE' => [] ]; $iterator = $DB->request($criteria); - $this->string($iterator->current()['name'])->isIdenticalTo('Computer import (by serial + uuid)'); + $this->assertSame('Computer import (by serial + uuid)', $iterator->current()['name']); //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps.teclib.infra-2018-10-03-08-42-36') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps.teclib.infra-2018-10-03-08-42-36', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check serial came from "MSN" node. - $this->string($computer->fields['serial'])->isIdenticalTo('640HP72'); + $this->assertSame('640HP72', $computer->fields['serial']); //Reimport, should not create a new computer $this->doInventory($json); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps.teclib.infra-2018-10-03-08-42-36') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps.teclib.infra-2018-10-03-08-42-36', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer - the same as before - $this->integer($agent['items_id'])->isIdenticalTo($computers_id); + $this->assertSame($computers_id, $agent['items_id']); $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check serial came from "MSN" node. - $this->string($computer->fields['serial'])->isIdenticalTo('640HP72'); + $this->assertSame('640HP72', $computer->fields['serial']); } public function testLastBoot() @@ -721,21 +725,21 @@ public function testLastBoot() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check last_boot came from "operatingsystem->boot_time" node. - $this->string($computer->fields['last_boot'])->isIdenticalTo('2020-06-09 07:58:08'); + $this->assertSame('2020-06-09 07:58:08', $computer->fields['last_boot']); } public function testInventoryChangeStatusOrNotFromManualInjection() @@ -750,7 +754,7 @@ public function testInventoryChangeStatusOrNotFromManualInjection() 'is_visible_computer' => 1 ] ); - $this->integer($state_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $state_1_id); $state_2_id = $state->add( [ @@ -760,7 +764,7 @@ public function testInventoryChangeStatusOrNotFromManualInjection() 'is_visible_computer' => 1 ] ); - $this->integer($state_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $state_2_id); //create computer manually with specific states before do an automatic inventory $computer = new \Computer(); @@ -793,40 +797,40 @@ public function testInventoryChangeStatusOrNotFromManualInjection() //per default, do not change states_id $this->login(); $conf = new \Glpi\Inventory\Conf(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'states_id_default' => '-1' ]) - )->isTrue(); + ); $this->logout(); $inventory = $this->doInventory($xml_source, true); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //load printer $computer->getFromDB($computers_id); - $this->integer($computer->fields['states_id'])->isEqualTo($state_1_id); + $this->assertSame($state_1_id, $computer->fields['states_id']); //restore default configuration $this->login(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'states_id_default' => $state_2_id ]) - )->isTrue(); + ); $this->logOut(); //inventory again $this->doInventory($xml_source, true); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //load printer $computer->getFromDB($computers_id); - $this->integer($computer->fields['states_id'])->isEqualTo($state_2_id); + $this->assertSame($state_2_id, $computer->fields['states_id']); } public function testInventoryChangeStatusOrNotFromAutomaticInventory() @@ -841,7 +845,7 @@ public function testInventoryChangeStatusOrNotFromAutomaticInventory() 'is_visible_computer' => 1 ] ); - $this->integer($state_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $state_1_id); @@ -865,40 +869,40 @@ public function testInventoryChangeStatusOrNotFromAutomaticInventory() //per default, do not change states_id $this->login(); $conf = new \Glpi\Inventory\Conf(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'states_id_default' => '-1' ]) - )->isTrue(); + ); $this->logout(); $inventory = $this->doInventory($xml_source, true); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //load printer $computer->getFromDB($computers_id); - $this->integer($computer->fields['states_id'])->isEqualTo(0); + $this->assertSame(0, $computer->fields['states_id']); //restore default configuration $this->login(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'states_id_default' => $state_1_id ]) - )->isTrue(); + ); $this->logOut(); //inventory again $this->doInventory($xml_source, true); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //load printer $computer->getFromDB($computers_id); - $this->integer($computer->fields['states_id'])->isEqualTo($state_1_id); + $this->assertSame($state_1_id, $computer->fields['states_id']); } public function testInventoryDefaultEntity() @@ -923,33 +927,33 @@ public function testInventoryDefaultEntity() $inventory = $this->doInventory($xml_source, true); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //load computer and check entities_id (0 by default) $computer->getFromDB($computers_id); - $this->integer($computer->fields['entities_id'])->isEqualTo(0); + $this->assertSame(0, $computer->fields['entities_id']); //per default, use entities_id 0 //so change entities_id to 1 $this->login(); $conf = new \Glpi\Inventory\Conf(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'entities_id_default' => 1 ]) - )->isTrue(); + ); $this->logout(); //second step : run same inventory and check that entities_id not change $inventory = $this->doInventory($xml_source, true); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //load computer and check entities_id is always 0 $computer->getFromDB($computers_id); - $this->integer($computer->fields['entities_id'])->isEqualTo(0); + $this->assertSame(0, $computer->fields['entities_id']); //third step : run new inventory and check that entities_id is 1 $xml_source = " @@ -972,11 +976,11 @@ public function testInventoryDefaultEntity() $inventory = $this->doInventory($xml_source, true); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //load computer and check entities_id 1 $computer->getFromDB($computers_id); - $this->integer($computer->fields['entities_id'])->isEqualTo(1); + $this->assertSame(1, $computer->fields['entities_id']); } public function testTransferWithLockedField() @@ -1001,11 +1005,11 @@ public function testTransferWithLockedField() $inventory = $this->doInventory($xml_source, true); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //load computer - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //test entities_id - $this->integer($computer->fields['entities_id'])->isEqualTo(0); + $this->assertSame(0, $computer->fields['entities_id']); //transer to another entity $doTransfer = \Entity::getUsedConfig('transfers_strategy', $computer->fields['entities_id'], 'transfers_id', 0); @@ -1019,14 +1023,14 @@ public function testTransferWithLockedField() $transfer->moveItems($item_to_transfer, 1, $transfer->fields); //reload computer - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //test entities_id - $this->integer($computer->fields['entities_id'])->isEqualTo(1); + $this->assertSame(1, $computer->fields['entities_id']); //one lock for entities_id $lockedfield = new \Lockedfield(); $locks = $lockedfield->find(['itemtype' => 'Computer', 'items_id' => $computers_id, "field" => "entities_id"]); - $this->integer(count($locks))->isIdenticalTo(1); + $this->assertCount(1, $locks); } public function testTransferWithoutLockedField() @@ -1051,11 +1055,11 @@ public function testTransferWithoutLockedField() $inventory = $this->doInventory($xml_source, true); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //load computer - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //test entities_id - $this->integer($computer->fields['entities_id'])->isEqualTo(0); + $this->assertSame(0, $computer->fields['entities_id']); //transer to another entity $doTransfer = \Entity::getUsedConfig('transfers_strategy', $computer->fields['entities_id'], 'transfers_id', 0); @@ -1069,13 +1073,13 @@ public function testTransferWithoutLockedField() $transfer->moveItems($item_to_transfer, 1, $transfer->fields); //reload computer - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //test entities_id - $this->integer($computer->fields['entities_id'])->isEqualTo(1); + $this->assertSame(1, $computer->fields['entities_id']); $lockedfield = new \Lockedfield(); $locks = $lockedfield->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($locks))->isIdenticalTo(0); + $this->assertCount(0, $locks); } public function testNetworkNames() @@ -1096,21 +1100,21 @@ public function testNetworkNames() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check last_boot came from "operatingsystem->boot_time" node. - $this->string($computer->fields['last_boot'])->isIdenticalTo('2020-06-09 07:58:08'); + $this->assertSame('2020-06-09 07:58:08', $computer->fields['last_boot']); $it = $DB->request([ 'SELECT' => ['id', 'name'], @@ -1120,7 +1124,7 @@ public function testNetworkNames() 'items_id' => $computers_id ] ]); - $this->integer(count($it))->isIdenticalTo(6); + $this->assertCount(6, $it); foreach ($it as $port) { if ($port['name'] === 'virbr0-nic') { @@ -1137,11 +1141,11 @@ public function testNetworkNames() ] ]); - $this->integer(count($netname_it))->isIdenticalTo(1); + $this->assertCount(1, $netname_it); $netname = $netname_it->current(); - $this->array($netname) - ->string['name']->isIdenticalTo(\Toolbox::slugify($port['name'])); + $this->assertIsArray($netname); + $this->assertSame(\Toolbox::slugify($port['name']), $netname['name']); } } @@ -1198,18 +1202,18 @@ public function testNetworkCards() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps.teclib.infra-2018-10-03-08-42-36') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps.teclib.infra-2018-10-03-08-42-36', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check created network cards $networkcards = $DB->request([ @@ -1219,7 +1223,7 @@ public function testNetworkCards() 'items_id' => $computers_id ] ]); - $this->integer(count($networkcards))->isIdenticalTo(1); + $this->assertCount(1, $networkcards); $item_networkcard = $DB->request([ 'FROM' => \Item_DeviceNetworkCard::getTable(), @@ -1228,7 +1232,7 @@ public function testNetworkCards() 'items_id' => $computers_id ] ]); - $this->integer(count($item_networkcard))->isIdenticalTo(1); + $this->assertCount(1, $item_networkcard); } public function testAssetTag() @@ -1261,20 +1265,20 @@ public function testAssetTag() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps.teclib.infra-2018-10-03-08-42-36') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps.teclib.infra-2018-10-03-08-42-36', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); - $this->string($computer->fields['otherserial'])->isIdenticalTo('other_serial'); + $this->assertSame('other_serial', $computer->fields['otherserial']); } public function testTransferNotAllowed() @@ -1301,20 +1305,18 @@ public function testTransferNotAllowed() //check created agent itemtype / deviceid / entities_id $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps.teclib.infra-2018-10-03-08-42-36') - ->string['itemtype']->isIdenticalTo('Computer') - ->integer['entities_id']->isIdenticalTo(0); //root entity - + $this->assertIsArray($agent); + $this->assertSame('glpixps.teclib.infra-2018-10-03-08-42-36', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame(0, $agent['entities_id']); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //load / test computer entities_id root - $this->boolean($computer->getFromDB($computers_id))->isTrue(); - $this->integer($computer->fields['entities_id'])->isEqualTo(0); - + $this->assertTrue($computer->getFromDB($computers_id)); + $this->assertSame(0, $computer->fields['entities_id']); //transfer to another entity $doTransfer = \Entity::getUsedConfig('transfers_strategy', $computer->fields['entities_id'], 'transfers_id', 0); @@ -1325,34 +1327,34 @@ public function testTransferNotAllowed() $transfer->moveItems($item_to_transfer, 1, $transfer->fields); //reload / test computer entities_id - $this->boolean($computer->getFromDB($computers_id))->isTrue(); - $this->integer($computer->fields['entities_id'])->isEqualTo(1); //another entity + $this->assertTrue($computer->getFromDB($computers_id)); + $this->assertSame(1, $computer->fields['entities_id']); //another entity //reload / test agent entities_id $reloaded_agent = new \Agent(); $reloaded_agent->getFromDB($agent['id']); - $this->integer($reloaded_agent->fields['entities_id'])->isEqualTo(0); //always root (only pc is transfered) + $this->assertSame(0, $reloaded_agent->fields['entities_id']); //always root (only pc is transfered) //prohibit the transfer from this entity $entity = new \Entity(); $entity->getFromDB(1); - $this->boolean($entity->update([ + $this->assertTrue($entity->update([ "id" => $entity->fields['id'], "transfers_id" => 0, //no transfert - ]))->isTrue(); + ])); //redo inventory $inventory = $this->doInventory($xml_source, true); //reload / test computer entities_id $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); - $this->integer($computer->fields['entities_id'])->isEqualTo(1); //another entity + $this->assertGreaterThan(0, $computers_id); + $this->assertTrue($computer->getFromDB($computers_id)); + $this->assertSame(1, $computer->fields['entities_id']); //another entity //reload / test agent entities_id $reloaded_agent = new \Agent(); $reloaded_agent->getFromDB($agent['id']); - $this->integer($reloaded_agent->fields['entities_id'])->isEqualTo(1); //another entity + $this->assertSame(1, $reloaded_agent->fields['entities_id']); //another entity } public function testTransferNotAllowedForSoftware() @@ -1391,33 +1393,32 @@ public function testTransferNotAllowedForSoftware() //check created agent itemtype / deviceid / entities_id $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps.teclib.infra-2018-10-03-08-42-36') - ->string['itemtype']->isIdenticalTo('Computer') - ->integer['entities_id']->isIdenticalTo(0); //root entity - + $this->assertIsArray($agent); + $this->assertSame('glpixps.teclib.infra-2018-10-03-08-42-36', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame(0, $agent['entities_id']); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //load / test computer entities_id root - $this->boolean($computer->getFromDB($computers_id))->isTrue(); - $this->integer($computer->fields['entities_id'])->isEqualTo(0); + $this->assertTrue($computer->getFromDB($computers_id)); + $this->assertSame(0, $computer->fields['entities_id']); //load / test software entities_id root $item_software = new \Item_SoftwareVersion(); $item_softwares = $item_software->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($item_softwares))->isIdenticalTo(1); - $this->integer(reset($item_softwares)['entities_id'])->isEqualTo(0); + $this->assertCount(1, $item_softwares); + $this->assertSame(0, reset($item_softwares)['entities_id']); //load softwareversion entities_id root $softwareversion = new \SoftwareVersion(); - $this->boolean($softwareversion->getFromDB(reset($item_softwares)['softwareversions_id']))->isTrue(); - $this->integer($softwareversion->fields['entities_id'])->isEqualTo(0); + $this->assertTrue($softwareversion->getFromDB(reset($item_softwares)['softwareversions_id'])); + $this->assertSame(0, $softwareversion->fields['entities_id']); //load software entities_id root $software = new \Software(); - $this->boolean($software->getFromDB($softwareversion->fields['softwares_id']))->isTrue(); - $this->integer($software->fields['entities_id'])->isEqualTo(0); + $this->assertTrue($software->getFromDB($softwareversion->fields['softwares_id'])); + $this->assertSame(0, $software->fields['entities_id']); @@ -1429,62 +1430,62 @@ public function testTransferNotAllowedForSoftware() $transfer->moveItems($item_to_transfer, 1, $transfer->fields); //reload / test computer entities_id sub - $this->boolean($computer->getFromDB($computers_id))->isTrue(); - $this->integer($computer->fields['entities_id'])->isEqualTo(1); //another entity + $this->assertTrue($computer->getFromDB($computers_id)); + $this->assertSame(1, $computer->fields['entities_id']); //another entity //reload / test agent entities_id $reloaded_agent = new \Agent(); $reloaded_agent->getFromDB($agent['id']); - $this->integer($reloaded_agent->fields['entities_id'])->isEqualTo(0); //always root (only pc is transfered) + $this->assertSame(0, $reloaded_agent->fields['entities_id']); //always root (only pc is transfered) //reload / test software entities_id sub $item_software = new \Item_SoftwareVersion(); $item_softwares = $item_software->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($item_softwares))->isIdenticalTo(1); - $this->integer(reset($item_softwares)['entities_id'])->isEqualTo(1); + $this->assertCount(1, $item_softwares); + $this->assertSame(1, reset($item_softwares)['entities_id']); //load sofware version entities_id sub $softwareversion = new \SoftwareVersion(); - $this->boolean($softwareversion->getFromDB(reset($item_softwares)['softwareversions_id']))->isTrue(); - $this->integer($softwareversion->fields['entities_id'])->isEqualTo(1); + $this->assertTrue($softwareversion->getFromDB(reset($item_softwares)['softwareversions_id'])); + $this->assertSame(1, $softwareversion->fields['entities_id']); //load software entities_id sub $software = new \Software(); - $this->boolean($software->getFromDB($softwareversion->fields['softwares_id']))->isTrue(); - $this->integer($software->fields['entities_id'])->isEqualTo(1); + $this->assertTrue($software->getFromDB($softwareversion->fields['softwares_id'])); + $this->assertSame(1, $software->fields['entities_id']); //prohibit the transfer from this entity $entity = new \Entity(); $entity->getFromDB(1); - $this->boolean($entity->update([ + $this->assertTrue($entity->update([ "id" => $entity->fields['id'], "transfers_strategy" => 0, //no transfert for computer "entities_strategy_software" => 0, //no transfert for software - ]))->isTrue(); + ])); //redo inventory $inventory = $this->doInventory($xml_source, true); //reload / test computer entities_id $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); - $this->integer($computer->fields['entities_id'])->isEqualTo(1); //another entity + $this->assertGreaterThan(0, $computers_id); + $this->assertTrue($computer->getFromDB($computers_id)); + $this->assertSame(1, $computer->fields['entities_id']); //another entity //reload / test agent entities_id $reloaded_agent = new \Agent(); $reloaded_agent->getFromDB($agent['id']); - $this->integer($reloaded_agent->fields['entities_id'])->isEqualTo(1); //another entity + $this->assertSame(1, $reloaded_agent->fields['entities_id']); //another entity //reload / test software entities_id sub $item_software = new \Item_SoftwareVersion(); $item_softwares = $item_software->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($item_softwares))->isIdenticalTo(1); - $this->integer(reset($item_softwares)['entities_id'])->isEqualTo(1); + $this->assertCount(1, $item_softwares); + $this->assertSame(1, reset($item_softwares)['entities_id']); //load sofware version entities_id sub $softwareversion = new \SoftwareVersion(); - $this->boolean($softwareversion->getFromDB(reset($item_softwares)['softwareversions_id']))->isTrue(); - $this->integer($softwareversion->fields['entities_id'])->isEqualTo(1); + $this->assertTrue($softwareversion->getFromDB(reset($item_softwares)['softwareversions_id'])); + $this->assertSame(1, $softwareversion->fields['entities_id']); //load software entities_id sub $software = new \Software(); - $this->boolean($software->getFromDB($softwareversion->fields['softwares_id']))->isTrue(); - $this->integer($software->fields['entities_id'])->isEqualTo(1); + $this->assertTrue($software->getFromDB($softwareversion->fields['softwares_id'])); + $this->assertSame(1, $software->fields['entities_id']); } public function testWorkgroup() @@ -1500,30 +1501,30 @@ public function testWorkgroup() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check domain has been created $domain = new \Domain(); - $this->boolean($domain->getFromDBByCrit(['name' => addslashes("workgroup'ed")]))->isTrue(); + $this->assertTrue($domain->getFromDBByCrit(['name' => addslashes("workgroup'ed")])); //check relation has been created $domain_item = new \Domain_Item(); - $this->boolean($domain_item->getFromDBByCrit(['domains_id' => $domain->fields['id']]))->isTrue(); + $this->assertTrue($domain_item->getFromDBByCrit(['domains_id' => $domain->fields['id']])); - $this->string($domain_item->fields['itemtype'])->isIdenticalTo('Computer'); - $this->integer($domain_item->fields['items_id'])->isIdenticalTo($computers_id); - $this->integer($domain_item->fields['domainrelations_id'])->isIdenticalTo(\DomainRelation::BELONGS); + $this->assertSame('Computer', $domain_item->fields['itemtype']); + $this->assertSame($computers_id, $domain_item->fields['items_id']); + $this->assertSame(\DomainRelation::BELONGS, $domain_item->fields['domainrelations_id']); $json_str = file_get_contents(self::INV_FIXTURES . 'computer_1.json'); $json = json_decode($json_str); @@ -1535,30 +1536,32 @@ public function testWorkgroup() //check domain has been created $first_id = $domain->fields['id']; $domain = new \Domain(); - $this->boolean($domain->getFromDBByCrit(['name' => addslashes("workgroup'ed another time")]))->isTrue(); + $this->assertTrue($domain->getFromDBByCrit(['name' => addslashes("workgroup'ed another time")])); //check relation has been created - and there is only one remaining $domain_item = new \Domain_Item(); - $this->boolean($domain_item->getFromDBByCrit(['domains_id' => $domain->fields['id']]))->isTrue(); - $this->boolean($domain_item->getFromDBByCrit(['domains_id' => $first_id]))->isFalse(); + $this->assertTrue($domain_item->getFromDBByCrit(['domains_id' => $domain->fields['id']])); + $this->assertFalse($domain_item->getFromDBByCrit(['domains_id' => $first_id])); //check if one has been added non dynamic $ndyn_domain = new \Domain(); - $this->integer( + $this->assertGreaterThan( + 0, $ndyn_domain->add([ 'name' => 'not dynamic', ]) - )->isGreaterThan(0); + ); $ndyn_item = new \Domain_Item(); - $this->integer( + $this->assertGreaterThan( + 0, $ndyn_item->add([ 'domains_id' => $ndyn_domain->fields['id'], 'itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0, ]) - )->isGreaterThan(0); + ); $json_str = file_get_contents(self::INV_FIXTURES . 'computer_1.json'); $json = json_decode($json_str); @@ -1570,12 +1573,12 @@ public function testWorkgroup() //check domain has been created $first_id = $domain->fields['id']; $domain = new \Domain(); - $this->boolean($domain->getFromDBByCrit(['name' => addslashes("workgroup'ed another time")]))->isTrue(); + $this->assertTrue($domain->getFromDBByCrit(['name' => addslashes("workgroup'ed another time")])); //check relation is still present - and non dynamic one as well $domain_item = new \Domain_Item(); - $this->boolean($domain_item->getFromDBByCrit(['domains_id' => $domain->fields['id']]))->isTrue(); - $this->boolean($domain_item->getFromDBByCrit(['domains_id' => $ndyn_domain->fields['id']]))->isTrue(); + $this->assertTrue($domain_item->getFromDBByCrit(['domains_id' => $domain->fields['id']])); + $this->assertTrue($domain_item->getFromDBByCrit(['domains_id' => $ndyn_domain->fields['id']])); } public function testEntityGlobalLockedField() @@ -1598,19 +1601,19 @@ public function testEntityGlobalLockedField() "; $lockedfield = new \Lockedfield(); - $this->integer($lockedfield->add(['itemtype' => 'Computer', 'items_id' => 0, 'field' => 'entities_id', 'is_global' => 1 ]))->isGreaterThan(0); + $this->assertGreaterThan(0, $lockedfield->add(['itemtype' => 'Computer', 'items_id' => 0, 'field' => 'entities_id', 'is_global' => 1 ])); $inventory = $this->doInventory($xml_source, true); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //load computer - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //test entities_id - $this->integer($computer->fields['entities_id'])->isEqualTo(0); + $this->assertSame(0, $computer->fields['entities_id']); $lockedfield = new \Lockedfield(); $locks = $lockedfield->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($locks))->isIdenticalTo(0); + $this->assertCount(0, $locks); } public function testErrorOnFieldUnicityChecks() @@ -1636,28 +1639,25 @@ public function testErrorOnFieldUnicityChecks() $this->createItem(\Computer::class, ['name' => $computer_name, 'entities_id' => $root_entity_id]); - $this->exception( - function () use ($computer_name) { - $inventory_request = new \Glpi\Inventory\Request(); - $inventory_request->handleRequest( - " - - - - {$computer_name} - 5BCB-25C1BB60B18F-5404A6A534C4 - - - 640HP72 - - FusionInventory-Inventory_v2.4.1-2.fc28 - - glpixps.teclib.infra-2018-10-03-08-42-36 - INVENTORY - " - ); - } - )->hasMessage('Unable to create item.'); + $inventory_request = new \Glpi\Inventory\Request(); + $this->expectExceptionMessage('Unable to create item.'); + $inventory_request->handleRequest( + " + + + + {$computer_name} + 5BCB-25C1BB60B18F-5404A6A534C4 + + + 640HP72 + + FusionInventory-Inventory_v2.4.1-2.fc28 + + glpixps.teclib.infra-2018-10-03-08-42-36 + INVENTORY + " + ); } public function testHwDescription() @@ -1673,21 +1673,21 @@ public function testHwDescription() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check hw description has been stored - $this->string($computer->fields['comment'])->isIdenticalTo("describ'ed from registry"); + $this->assertSame("describ'ed from registry", $computer->fields['comment']); } public function testOsCommentRuleLocation() @@ -1698,7 +1698,7 @@ public function testOsCommentRuleLocation() $locations_id = $location->add([ 'name' => 'Caen', ]); - $this->integer($locations_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $locations_id); $rule = new \Rule(); $input = [ @@ -1709,7 +1709,7 @@ public function testOsCommentRuleLocation() 'ranking' => 1 ]; $rules_id = $rule->add($input); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); $rulecriteria = new \RuleCriteria(); $input = [ @@ -1718,7 +1718,7 @@ public function testOsCommentRuleLocation() 'pattern' => "Caen", 'condition' => \Rule::PATTERN_CONTAIN ]; - $this->integer($rulecriteria->add($input))->isGreaterThan(0); + $this->assertGreaterThan(0, $rulecriteria->add($input)); $ruleaction = new \RuleAction(); $input = [ @@ -1727,7 +1727,7 @@ public function testOsCommentRuleLocation() 'field' => 'locations_id', 'value' => $locations_id ]; - $this->integer($ruleaction->add($input))->isGreaterThan(0); + $this->assertGreaterThan(0, $ruleaction->add($input)); $xml_source = " @@ -1750,18 +1750,17 @@ public function testOsCommentRuleLocation() //check created agent itemtype / deviceid / entities_id $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps.teclib.infra-2018-10-03-08-42-36') - ->string['itemtype']->isIdenticalTo('Computer') - ->integer['entities_id']->isIdenticalTo(0); //root entity - + $this->assertIsArray($agent); + $this->assertSame('glpixps.teclib.infra-2018-10-03-08-42-36', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame(0, $agent['entities_id']); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //load / test computer entities_id root - $this->boolean($computer->getFromDB($computers_id))->isTrue(); - $this->integer($computer->fields['locations_id'])->isEqualTo($locations_id); + $this->assertTrue($computer->getFromDB($computers_id)); + $this->assertSame($locations_id, $computer->fields['locations_id']); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Controller.php b/phpunit/functional/Glpi/Inventory/Assets/Controller.php similarity index 87% rename from tests/functional/Glpi/Inventory/Assets/Controller.php rename to phpunit/functional/Glpi/Inventory/Assets/Controller.php index 1fe03e32f45..41a1f6e1595 100644 --- a/tests/functional/Glpi/Inventory/Assets/Controller.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Controller.php @@ -41,7 +41,7 @@ class Controller extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -105,7 +105,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\Controller($computer, $json->content->controllers); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -114,8 +114,10 @@ public function testHandle() //first, check there are no controller linked to this computer $idc = new \Item_DeviceControl(); - $this->boolean($idc->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A controller is already linked to computer!'); + $this->assertFalse( + $idc->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A controller is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -128,13 +130,15 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Controller($computer, $json->content->controllers); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($idc->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Controller has not been linked to computer :('); + $this->assertTrue( + $idc->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Controller has not been linked to computer :(' + ); } public function testInventoryUpdate() @@ -188,20 +192,20 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $manufacturer = new \Manufacturer(); $manufacturers_id = $manufacturer->add([ 'name' => 'Intel Corporation' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $controller_1_id = $device_control->add([ 'designation' => 'Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor Host Bridge/DRAM Registers', 'manufacturers_id' => $manufacturers_id, 'entities_id' => 0 ]); - $this->integer($controller_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $controller_1_id); $item_controller_1_id = $item_control->add([ 'items_id' => $computers_id, @@ -219,33 +223,33 @@ public function testInventoryUpdate() 'manufacturers_id' => $manufacturers_id, 'entities_id' => 0 ]); - $this->integer($controller_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $controller_2_id); $item_controller_2_id = $item_control->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicecontrols_id' => $controller_2_id ]); - $this->integer($item_controller_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_controller_2_id); $controller_3_id = $device_control->add([ 'designation' => 'My Controller', 'manufacturers_id' => $manufacturers_id, 'entities_id' => 0 ]); - $this->integer($controller_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $controller_3_id); $item_controller_3_id = $item_control->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicecontrols_id' => $controller_3_id ]); - $this->integer($item_controller_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_controller_3_id); $controllers = $item_control->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($controllers))->isIdenticalTo(3); + $this->assertCount(3, $controllers); foreach ($controllers as $controller) { - $this->variable($controller['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $controller['is_dynamic']); } //computer inventory knows only "Xeon" and "NVMe SSD" controllers @@ -253,19 +257,19 @@ public function testInventoryUpdate() //we still have 3 controllers $controllers = $device_control->find(); - $this->integer(count($controllers))->isIdenticalTo(3); + $this->assertCount(3, $controllers); //we still have 3 controllers items linked to the computer $controllers = $item_control->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($controllers))->isIdenticalTo(3); + $this->assertCount(3, $controllers); //controllers present in the inventory source are now dynamic $controllers = $item_control->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($controllers))->isIdenticalTo(2); + $this->assertCount(2, $controllers); //controller not present in the inventory is still not dynamic $controllers = $item_control->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($controllers))->isIdenticalTo(1); + $this->assertCount(1, $controllers); //Redo inventory, but with removed "NVMe SSD" controller $xml_source = " @@ -299,18 +303,18 @@ public function testInventoryUpdate() //we still have 3 controllers $controllers = $device_control->find(); - $this->integer(count($controllers))->isIdenticalTo(3); + $this->assertCount(3, $controllers); //we now have 2 controllers linked to computer only $controllers = $item_control->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($controllers))->isIdenticalTo(2); + $this->assertCount(2, $controllers); //controller present in the inventory source is still dynamic $controllers = $item_control->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($controllers))->isIdenticalTo(1); + $this->assertCount(1, $controllers); //controller not present in the inventory is still not dynamic $controllers = $item_control->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($controllers))->isIdenticalTo(1); + $this->assertCount(1, $controllers); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Device.php b/phpunit/functional/Glpi/Inventory/Assets/Device.php similarity index 87% rename from tests/functional/Glpi/Inventory/Assets/Device.php rename to phpunit/functional/Glpi/Inventory/Assets/Device.php index 6b787c7f44d..11968f9fe41 100644 --- a/tests/functional/Glpi/Inventory/Assets/Device.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Device.php @@ -41,12 +41,11 @@ class Device extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return []; } - public function testInventoryUpdateMemory() { global $DB; @@ -95,17 +94,17 @@ public function testInventoryUpdateMemory() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); $computer->getFromDB($computers_id); //memories present from the inventory source are dynamic $memories = $item_mem->find(['itemtype' => \Computer::class, 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($memories))->isIdenticalTo(2); + $this->assertCount(2, $memories); $data_to_check = []; @@ -122,7 +121,7 @@ public function testInventoryUpdateMemory() ]; //create infocom $id = $info_com->add($input); - $this->integer($id)->isGreaterThan(0); + $this->assertGreaterThan(0, $id); $input['id'] = $id; $data_to_check[] = $input; } @@ -132,18 +131,18 @@ public function testInventoryUpdateMemory() //memory present in the inventory source is still dynamic $memories = $item_mem->find(['itemtype' => \Computer::class, 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($memories))->isIdenticalTo(2); + $this->assertCount(2, $memories); //check item_device_memory is the same from first step foreach ($data_to_check as $data_value) { $memories = $item_mem->find(['id' => $data_value['items_id'], "itemtype" => \Computer::class, 'is_dynamic' => 1]); - $this->integer(count($memories))->isIdenticalTo(1); + $this->assertCount(1, $memories); } //check infocom still exists foreach ($data_to_check as $data_value) { $info_coms = $info_com->find(['id' => $data_value['id'], "buy_date" => $infocom_buy_date, "value" => $infocom_value]); - $this->integer(count($info_coms))->isIdenticalTo(1); + $this->assertCount(1, $info_coms); } } @@ -199,17 +198,17 @@ public function testInventoryUpdateDrive() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); $computer->getFromDB($computers_id); //drives present from the inventory source are dynamic $drives = $item_drv->find(['itemtype' => \Computer::class, 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($drives))->isIdenticalTo(2); + $this->assertCount(2, $drives); $data_to_check = []; @@ -226,7 +225,7 @@ public function testInventoryUpdateDrive() ]; //create infocom $id = $info_com->add($input); - $this->integer($id)->isGreaterThan(0); + $this->assertGreaterThan(0, $id); $input['id'] = $id; $data_to_check[] = $input; } @@ -236,18 +235,18 @@ public function testInventoryUpdateDrive() //drives present in the inventory source are still dynamic $drives = $item_drv->find(['itemtype' => \Computer::class, 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($drives))->isIdenticalTo(2); + $this->assertCount(2, $drives); //check item_device_memory is the same from first step foreach ($data_to_check as $data_value) { $drives = $item_drv->find(['id' => $data_value['items_id'], "itemtype" => \Computer::class, 'is_dynamic' => 1]); - $this->integer(count($drives))->isIdenticalTo(1); + $this->assertCount(1, $drives); } //check infocom still exists foreach ($data_to_check as $data_value) { $info_coms = $info_com->find(['id' => $data_value['id'], "buy_date" => $infocom_buy_date, "value" => $infocom_value]); - $this->integer(count($info_coms))->isIdenticalTo(1); + $this->assertCount(1, $info_coms); } } @@ -298,17 +297,17 @@ public function testInventoryLogOnUpdateMemory() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); $computer->getFromDB($computers_id); //memories present from the inventory source are dynamic $memories = $item_mem->find(['itemtype' => \Computer::class, 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($memories))->isIdenticalTo(2); + $this->assertCount(2, $memories); //check for expected logs $nblogsnow = countElementsInTable(\Log::getTable()); @@ -318,7 +317,7 @@ public function testInventoryLogOnUpdateMemory() 'itemtype' => \Item_DeviceMemory::class ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //redo inventory and update memory capacity 8192 => 4096 $xml_source = " @@ -362,17 +361,17 @@ public function testInventoryLogOnUpdateMemory() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); $computer->getFromDB($computers_id); //memories present from the inventory source are dynamic $memories = $item_mem->find(['itemtype' => \Computer::class, 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($memories))->isIdenticalTo(2); + $this->assertCount(2, $memories); //check for expected logs $nblogsnow = countElementsInTable(\Log::getTable()); @@ -382,13 +381,13 @@ public function testInventoryLogOnUpdateMemory() 'itemtype' => \Item_DeviceMemory::class, ] ]); - $this->integer(count($logs))->isIdenticalTo(2); //for each memory module + $this->assertCount(2, $logs); //for each memory module foreach ($logs as $key => $value) { - $this->string($value['old_value'])->isIdenticalTo('8192'); - $this->string($value['new_value'])->isIdenticalTo('4096'); - $this->integer($value['id_search_option'])->isIdenticalTo(20); //capacity SO - $this->array($memories)->hasKey($value['items_id']); //concerned item_devicememories + $this->assertSame('8192', $value['old_value']); + $this->assertSame('4096', $value['new_value']); + $this->assertSame(20, $value['id_search_option']); //capacity SO + $this->assertArrayHasKey($value['items_id'], $memories); //concerned item_devicememories } } } diff --git a/tests/functional/Glpi/Inventory/Assets/Drive.php b/phpunit/functional/Glpi/Inventory/Assets/Drive.php similarity index 83% rename from tests/functional/Glpi/Inventory/Assets/Drive.php rename to phpunit/functional/Glpi/Inventory/Assets/Drive.php index a52b7bb133a..1eda90e2de4 100644 --- a/tests/functional/Glpi/Inventory/Assets/Drive.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Drive.php @@ -41,7 +41,7 @@ class Drive extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ //hdd @@ -104,11 +104,12 @@ public function testPrepare($xml, $expected) $result = $asset->prepare(); if (!$asset->isDrive($json->content->storages[0])) { - //work with a HDD - $this->array($result)->isEmpty(); + //work with a HDD + $this->assertIsArray($result); + $this->assertEmpty($result); $result = $asset->getPreparedHarddrives(); } - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -118,10 +119,14 @@ public function testHandle() //first, check there are no controller linked to this computer $idd = new \Item_DeviceDrive(); $idh = new \Item_DeviceHardDrive(); - $this->boolean($idd->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A drive is already linked to computer!'); - $this->boolean($idh->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A hard drive is already linked to computer!'); + $this->assertFalse( + $idd->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A drive is already linked to computer!' + ); + $this->assertFalse( + $idh->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A hard drive is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -134,16 +139,19 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Drive($computer, $json->content->storages); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - //is a harddrive - $this->array($result)->isEmpty(); + //is a harddrive + $this->assertIsArray($result); + $this->assertEmpty($result); $result = $asset->getPreparedHarddrives(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($idh->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Hard disk has not been linked to computer :('); + $this->assertTrue( + $idh->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Hard disk has not been linked to computer :(' + ); } public function testInventoryUpdate() @@ -193,19 +201,19 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $manufacturer = new \Manufacturer(); $manufacturers_id = $manufacturer->add([ 'name' => 'Samsung' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $interface = new \InterfaceType(); $interfacetypes_id = $interface->add([ 'name' => 'CDROM' ]); - $this->integer($interfacetypes_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $interfacetypes_id); $drive_1_id = $device_drive->add([ 'designation' => 'CD-ROM drive', @@ -213,19 +221,19 @@ public function testInventoryUpdate() 'interfacetypes_id' => $interfacetypes_id, 'entities_id' => 0 ]); - $this->integer($drive_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $drive_1_id); $item_drive_1_id = $item_drive->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicedrives_id' => $drive_1_id ]); - $this->integer($item_drive_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_drive_1_id); $interfacetypes_id = $interface->add([ 'name' => 'CD-ROM' ]); - $this->integer($interfacetypes_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $interfacetypes_id); $drive_2_id = $device_drive->add([ 'designation' => 'Lecteur de CD-ROM', @@ -233,14 +241,14 @@ public function testInventoryUpdate() 'interfacetypes_id' => $interfacetypes_id, 'entities_id' => 0 ]); - $this->integer($drive_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $drive_2_id); $item_drive_2_id = $item_drive->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicedrives_id' => $drive_2_id ]); - $this->integer($item_drive_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_drive_2_id); $interfacetypes_id = $interface->add([ 'name' => 'DVD Writer' @@ -252,19 +260,19 @@ public function testInventoryUpdate() 'interfacetypes_id' => $interfacetypes_id, 'entities_id' => 0 ]); - $this->integer($drive_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $drive_3_id); $item_drive_3_id = $item_drive->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicedrives_id' => $drive_3_id ]); - $this->integer($item_drive_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_drive_3_id); $drives = $item_drive->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($drives))->isIdenticalTo(3); + $this->assertCount(3, $drives); foreach ($drives as $drive) { - $this->variable($drive['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $drive['is_dynamic']); } //computer inventory knows only "hp" and "lite-on" drives @@ -272,19 +280,19 @@ public function testInventoryUpdate() //we still have 3 drives $drives = $device_drive->find(); - $this->integer(count($drives))->isIdenticalTo(3); + $this->assertCount(3, $drives); //we still have 3 drives items linked to the computer $drives = $item_drive->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($drives))->isIdenticalTo(3); + $this->assertCount(3, $drives); //drives present in the inventory source are now dynamic $drives = $item_drive->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($drives))->isIdenticalTo(2); + $this->assertCount(2, $drives); //drive not present in the inventory is still not dynamic $drives = $item_drive->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($drives))->isIdenticalTo(1); + $this->assertCount(1, $drives); //Redo inventory, but with removed "lite-on" drive $xml_source = " @@ -316,19 +324,19 @@ public function testInventoryUpdate() //we still have 3 drives $drives = $device_drive->find(); - $this->integer(count($drives))->isIdenticalTo(3); + $this->assertCount(3, $drives); //we now have 2 drives linked to computer only $drives = $item_drive->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($drives))->isIdenticalTo(2); + $this->assertCount(2, $drives); //drive present in the inventory source is still dynamic $drives = $item_drive->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($drives))->isIdenticalTo(1); + $this->assertCount(1, $drives); //drive not present in the inventory is still not dynamic $drives = $item_drive->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($drives))->isIdenticalTo(1); + $this->assertCount(1, $drives); } public function testInventoryUpdateHardDrive() @@ -384,20 +392,20 @@ public function testInventoryUpdateHardDrive() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $manufacturer = new \Manufacturer(); $manufacturers_id = $manufacturer->add([ 'name' => 'Samsung' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $interface = new \InterfaceType(); - $this->boolean( + $this->assertTrue( $interface->getFromDBByCrit(['name' => 'IDE']) - )->isTrue(); + ); $interfacetypes_id = $interface->fields['id']; - $this->integer($interfacetypes_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $interfacetypes_id); $harddrive_1_id = $device_hdd->add([ 'designation' => 'PM951 NVMe SAMSUNG 256GB', @@ -405,7 +413,7 @@ public function testInventoryUpdateHardDrive() 'interfacetypes_id' => $interfacetypes_id, 'entities_id' => 0 ]); - $this->integer($harddrive_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $harddrive_1_id); $item_harddrive_1_id = $item_hdd->add([ 'items_id' => $computers_id, @@ -413,7 +421,7 @@ public function testInventoryUpdateHardDrive() 'deviceharddrives_id' => $harddrive_1_id, 'serial' => 'S29NNXAH146764' ]); - $this->integer($item_harddrive_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_harddrive_1_id); $harddrive_2_id = $device_hdd->add([ 'designation' => 'HGST HTS725032A7E630', @@ -421,7 +429,7 @@ public function testInventoryUpdateHardDrive() 'interfacetypes_id' => $interfacetypes_id, 'entities_id' => 0 ]); - $this->integer($harddrive_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $harddrive_2_id); $item_harddrive_2_id = $item_hdd->add([ 'items_id' => $computers_id, @@ -429,7 +437,7 @@ public function testInventoryUpdateHardDrive() 'deviceharddrives_id' => $harddrive_2_id, 'serial' => '131005TF0401Y11K4NNN' ]); - $this->integer($item_harddrive_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_harddrive_2_id); $harddrive_3_id = $device_hdd->add([ 'designation' => 'My Hard Drive', @@ -437,19 +445,19 @@ public function testInventoryUpdateHardDrive() 'interfacetypes_id' => $interfacetypes_id, 'entities_id' => 0 ]); - $this->integer($harddrive_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $harddrive_3_id); $item_harddrive_3_id = $item_hdd->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'deviceharddrives_id' => $harddrive_3_id ]); - $this->integer($item_harddrive_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_harddrive_3_id); $harddrives = $item_hdd->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($harddrives))->isIdenticalTo(3); + $this->assertCount(3, $harddrives); foreach ($harddrives as $harddrive) { - $this->variable($harddrive['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $harddrive['is_dynamic']); } //computer inventory knows only "PM951 NVMe SAMSUNG 256GB" and "HGST HTS725032A7E630" harddrives @@ -457,19 +465,19 @@ public function testInventoryUpdateHardDrive() //we still have 3 harddrives $harddrives = $device_hdd->find(); - $this->integer(count($harddrives))->isIdenticalTo(3); + $this->assertCount(3, $harddrives); //we still have 3 harddrives items linked to the computer $harddrives = $item_hdd->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($harddrives))->isIdenticalTo(3); + $this->assertCount(3, $harddrives); //harddrives present in the inventory source are now dynamic $harddrives = $item_hdd->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($harddrives))->isIdenticalTo(2); + $this->assertCount(2, $harddrives); //harddrive not present in the inventory is still not dynamic $harddrives = $item_hdd->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($harddrives))->isIdenticalTo(1); + $this->assertCount(1, $harddrives); //Redo inventory, but with removed "HGST HTS725032A7E630" harddrive $xml_source = " @@ -501,18 +509,18 @@ public function testInventoryUpdateHardDrive() //we still have 3 harddrives $harddrives = $device_hdd->find(); - $this->integer(count($harddrives))->isIdenticalTo(3); + $this->assertCount(3, $harddrives); //we now have 2 harddrives linked to computer only $harddrives = $item_hdd->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($harddrives))->isIdenticalTo(2); + $this->assertCount(2, $harddrives); //harddrive present in the inventory source is still dynamic $harddrives = $item_hdd->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($harddrives))->isIdenticalTo(1); + $this->assertCount(1, $harddrives); //harddrive not present in the inventory is still not dynamic $harddrives = $item_hdd->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($harddrives))->isIdenticalTo(1); + $this->assertCount(1, $harddrives); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Firmware.php b/phpunit/functional/Glpi/Inventory/Assets/Firmware.php similarity index 85% rename from tests/functional/Glpi/Inventory/Assets/Firmware.php rename to phpunit/functional/Glpi/Inventory/Assets/Firmware.php index 72771053249..fdbed3b3af0 100644 --- a/tests/functional/Glpi/Inventory/Assets/Firmware.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Firmware.php @@ -41,7 +41,7 @@ class Firmware extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -95,7 +95,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\Firmware($computer, (array)$json->content->firmwares); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -104,8 +104,10 @@ public function testHandle() //first, check there are no controller linked to this computer $idf = new \Item_DeviceFirmware(); - $this->boolean($idf->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A firmware is already linked to computer!'); + $this->assertFalse( + $idf->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A firmware is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -118,13 +120,15 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Firmware($computer, (array)$json->content->firmwares); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($idf->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Firmware has not been linked to computer :('); + $this->assertTrue( + $idf->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Firmware has not been linked to computer :(' + ); } public function testLockedFieldandFirmware() @@ -163,26 +167,26 @@ public function testLockedFieldandFirmware() "; //add lockedfield to check for DB warning on manage DeviceFirmware lockedField - $this->integer( + $this->assertGreaterThan( + 0, (int)$DB->insert("glpi_lockedfields", ["field" => mt_rand(), "itemtype" => "Item_DeviceFirmware", "is_global" => 0]) - )->isGreaterThan(0); - + ); //computer inventory knows only "UCS 6248UP 48-Port" and "HP-HttpMg-Version" firmwares $this->doInventory($xml_source, true); //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //we still have 2 firmwares + 1 bios $fws = $device_fw->find(); - $this->integer(count($fws))->isIdenticalTo(3); + $this->assertCount(3, $fws); //we still have 2 firmwares items linked to the computer $fws = $item_fw->find(['itemtype' => 'Computer', 'items_id' => $agent['items_id']]); - $this->integer(count($fws))->isIdenticalTo(2); + $this->assertCount(2, $fws); } public function testInventoryUpdate() @@ -226,19 +230,19 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $manufacturer = new \Manufacturer(); $manufacturers_id = $manufacturer->add([ 'name' => 'Cisco' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $type = new \DeviceFirmwareType(); $types_id = $type->add([ 'name' => 'device' ]); - $this->integer($types_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $types_id); $fw_1_id = $device_fw->add([ 'designation' => 'UCS 6248UP 48-Port', @@ -247,26 +251,26 @@ public function testInventoryUpdate() 'version' => '5.0(3)N2(4.02b)', 'entities_id' => 0 ]); - $this->integer($fw_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $fw_1_id); $item_fw_1_id = $item_fw->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicefirmwares_id' => $fw_1_id ]); - $this->integer($item_fw_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_fw_1_id); $manufacturer = new \Manufacturer(); $manufacturers_id = $manufacturer->add([ 'name' => 'HP' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $type = new \DeviceFirmwareType(); $types_id = $type->add([ 'name' => 'system' ]); - $this->integer($types_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $types_id); $fw_2_id = $device_fw->add([ 'designation' => 'HP-HttpMg-Version', @@ -275,14 +279,14 @@ public function testInventoryUpdate() 'version' => 'WC.16.02.0003', 'entities_id' => 0 ]); - $this->integer($fw_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $fw_2_id); $item_fw_2_id = $item_fw->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicefirmwares_id' => $fw_2_id ]); - $this->integer($item_fw_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_fw_2_id); $fw_3_id = $device_fw->add([ 'designation' => 'My Firmware', @@ -290,19 +294,19 @@ public function testInventoryUpdate() 'devicefirmwaretypes_id' => $types_id, 'entities_id' => 0 ]); - $this->integer($fw_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $fw_3_id); $item_fw_3_id = $item_fw->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicefirmwares_id' => $fw_3_id ]); - $this->integer($item_fw_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_fw_3_id); $firmwares = $item_fw->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($firmwares))->isIdenticalTo(3); + $this->assertCount(3, $firmwares); foreach ($firmwares as $firmware) { - $this->variable($firmware['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $firmware['is_dynamic']); } //computer inventory knows only "UCS 6248UP 48-Port" and "HP-HttpMg-Version" firmwares @@ -310,19 +314,19 @@ public function testInventoryUpdate() //we still have 3 firmwares + 1 bios $fws = $device_fw->find(); - $this->integer(count($fws))->isIdenticalTo(3 + 1); + $this->assertCount(3 + 1, $fws); //we still have 3 firmwares items linked to the computer $fws = $item_fw->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($fws))->isIdenticalTo(3); + $this->assertCount(3, $fws); //firmwares present in the inventory source are now dynamic $fws = $item_fw->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($fws))->isIdenticalTo(2); + $this->assertCount(2, $fws); //firmware not present in the inventory is still not dynamic $fws = $item_fw->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($fws))->isIdenticalTo(1); + $this->assertCount(1, $fws); //Redo inventory, but with removed "HP-HttpMg-Version" firmware $xml_source = " @@ -351,18 +355,18 @@ public function testInventoryUpdate() //we still have 3 firmwares + 1 bios $fws = $device_fw->find(); - $this->integer(count($fws))->isIdenticalTo(3 + 1); + $this->assertCount(3 + 1, $fws); //we now have 2 firmwares linked to computer only $fws = $item_fw->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($fws))->isIdenticalTo(2); + $this->assertCount(2, $fws); //firmware present in the inventory source is still dynamic $fws = $item_fw->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($fws))->isIdenticalTo(1); + $this->assertCount(1, $fws); //firmware not present in the inventory is still not dynamic $fws = $item_fw->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($fws))->isIdenticalTo(1); + $this->assertCount(1, $fws); } } diff --git a/tests/functional/Glpi/Inventory/Assets/GraphicCard.php b/phpunit/functional/Glpi/Inventory/Assets/GraphicCard.php similarity index 84% rename from tests/functional/Glpi/Inventory/Assets/GraphicCard.php rename to phpunit/functional/Glpi/Inventory/Assets/GraphicCard.php index 24c41dcd88d..3fe6b92a0b1 100644 --- a/tests/functional/Glpi/Inventory/Assets/GraphicCard.php +++ b/phpunit/functional/Glpi/Inventory/Assets/GraphicCard.php @@ -41,7 +41,7 @@ class GraphicCard extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -92,7 +92,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\GraphicCard($computer, $json->content->videos); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -101,8 +101,10 @@ public function testHandle() //first, check there are no controller linked to this computer $idg = new \Item_DeviceGraphicCard(); - $this->boolean($idg->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A graphic cardis already linked to computer!'); + $this->assertFalse( + $idg->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A graphic cardis already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -115,13 +117,15 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\GraphicCard($computer, $json->content->videos); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($idg->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Graphic card has not been linked to computer :('); + $this->assertTrue( + $idg->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Graphic card has not been linked to computer :(' + ); } public function testInventoryUpdate() @@ -162,54 +166,54 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $gc_1_id = $device_gc->add([ 'designation' => 'ATI Radeon X1600', 'chipset' => 'ATY,RadeonX1600', 'entities_id' => 0 ]); - $this->integer($gc_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $gc_1_id); $item_gc_1_id = $item_gc->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicegraphiccards_id' => $gc_1_id ]); - $this->integer($item_gc_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_gc_1_id); $gc_2_id = $device_gc->add([ 'designation' => 'Intel(R) HD Graphics 530', 'chipset' => 'Intel(R) HD Graphics Family', 'entities_id' => 0 ]); - $this->integer($gc_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $gc_2_id); $item_gc_2_id = $item_gc->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicegraphiccards_id' => $gc_2_id ]); - $this->integer($item_gc_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_gc_2_id); $gc_3_id = $device_gc->add([ 'designation' => 'My Graphic Card', 'chipset' => 'My chipset', 'entities_id' => 0 ]); - $this->integer($gc_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $gc_3_id); $item_gc_3_id = $item_gc->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicegraphiccards_id' => $gc_3_id ]); - $this->integer($item_gc_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_gc_3_id); $gcs = $item_gc->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($gcs))->isIdenticalTo(3); + $this->assertCount(3, $gcs); foreach ($gcs as $gc) { - $this->variable($gc['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $gc['is_dynamic']); } //computer inventory knows only "ATI" and "Intel" graphic cards @@ -217,19 +221,19 @@ public function testInventoryUpdate() //we still have 3 graphic cards $gcs = $device_gc->find(); - $this->integer(count($gcs))->isIdenticalTo(3); + $this->assertCount(3, $gcs); //we still have 3 graphic cards items linked to the computer $gcs = $item_gc->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($gcs))->isIdenticalTo(3); + $this->assertCount(3, $gcs); //graphic cards present in the inventory source are now dynamic $gcs = $item_gc->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($gcs))->isIdenticalTo(2); + $this->assertCount(2, $gcs); //graphic card not present in the inventory is still not dynamic $gcs = $item_gc->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($gcs))->isIdenticalTo(1); + $this->assertCount(1, $gcs); //Redo inventory, but with removed "Intel" graphic card $xml_source = " @@ -257,18 +261,18 @@ public function testInventoryUpdate() //we still have 3 graphic cards $gcs = $device_gc->find(); - $this->integer(count($gcs))->isIdenticalTo(3); + $this->assertCount(3, $gcs); //we now have 2 graphic cards linked to computer only $gcs = $item_gc->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($gcs))->isIdenticalTo(2); + $this->assertCount(2, $gcs); //graphic card present in the inventory source is still dynamic $gcs = $item_gc->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($gcs))->isIdenticalTo(1); + $this->assertCount(1, $gcs); //graphic card not present in the inventory is still not dynamic $gcs = $item_gc->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($gcs))->isIdenticalTo(1); + $this->assertCount(1, $gcs); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Memory.php b/phpunit/functional/Glpi/Inventory/Assets/Memory.php similarity index 84% rename from tests/functional/Glpi/Inventory/Assets/Memory.php rename to phpunit/functional/Glpi/Inventory/Assets/Memory.php index f4f298b8653..5bd5a740b16 100644 --- a/tests/functional/Glpi/Inventory/Assets/Memory.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Memory.php @@ -41,7 +41,7 @@ class Memory extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -82,7 +82,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\Memory($computer, $json->content->memories); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -91,8 +91,10 @@ public function testHandle() //first, check there are no controller linked to this computer $idm = new \Item_DeviceMemory(); - $this->boolean($idm->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A memory is already linked to computer!'); + $this->assertFalse( + $idm->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A memory is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -105,13 +107,15 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Memory($computer, $json->content->memories); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($idm->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Memory has not been linked to computer :('); + $this->assertTrue( + $idm->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Memory has not been linked to computer :(' + ); } public function testInventoryUpdate() @@ -163,19 +167,19 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $manufacturer = new \Manufacturer(); $manufacturers_id = $manufacturer->add([ 'name' => 'Samsung' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $type = new \DeviceMemoryType(); $types_id = $type->add([ 'name' => 'DDR4' ]); - $this->integer($types_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $types_id); $mem_1_id = $device_mem->add([ 'designation' => 'DDR4 - SODIMM', @@ -184,7 +188,7 @@ public function testInventoryUpdate() 'frequence' => '2133', 'entities_id' => 0 ]); - $this->integer($mem_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $mem_1_id); $item_mem_1_id = $item_mem->add([ 'items_id' => $computers_id, @@ -193,7 +197,7 @@ public function testInventoryUpdate() 'serial' => '97842456', 'size' => '8192' ]); - $this->integer($item_mem_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_mem_1_id); $item_mem_2_id = $item_mem->add([ 'items_id' => $computers_id, @@ -202,7 +206,7 @@ public function testInventoryUpdate() 'serial' => '97842457', 'size' => '8192' ]); - $this->integer($item_mem_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_mem_2_id); $mem_3_id = $device_mem->add([ 'designation' => 'DDR3 - SODIMM', @@ -211,19 +215,19 @@ public function testInventoryUpdate() 'frequence' => '2133', 'entities_id' => 0 ]); - $this->integer($mem_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $mem_3_id); $item_mem_3_id = $item_mem->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicememories_id' => $mem_3_id ]); - $this->integer($item_mem_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_mem_3_id); $memories = $item_mem->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($memories))->isIdenticalTo(3); + $this->assertCount(3, $memories); foreach ($memories as $memory) { - $this->variable($memory['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $memory['is_dynamic']); } //computer inventory knows only "Bottom-Slot 1(left)" and "Bottom-Slot 2(right)" memories @@ -231,19 +235,19 @@ public function testInventoryUpdate() //we still have 2 memory devices $memories = $device_mem->find(); - $this->integer(count($memories))->isIdenticalTo(2); + $this->assertCount(2, $memories); //we still have 3 memories items linked to the computer $memories = $item_mem->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($memories))->isIdenticalTo(3); + $this->assertCount(3, $memories); //memories present in the inventory source are now dynamic $memories = $item_mem->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($memories))->isIdenticalTo(2); + $this->assertCount(2, $memories); //memory not present in the inventory is still not dynamic $memories = $item_mem->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($memories))->isIdenticalTo(1); + $this->assertCount(1, $memories); //Redo inventory, but with removed "Bottom-Slot 2(right)" memory $xml_source = " @@ -276,18 +280,18 @@ public function testInventoryUpdate() //we now have only 2 memories $memories = $device_mem->find(); - $this->integer(count($memories))->isIdenticalTo(2); + $this->assertCount(2, $memories); //we now have 2 memories linked to computer only $memories = $item_mem->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($memories))->isIdenticalTo(2); + $this->assertCount(2, $memories); //memory present in the inventory source is still dynamic $memories = $item_mem->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($memories))->isIdenticalTo(1); + $this->assertCount(1, $memories); //memory not present in the inventory is still not dynamic $memories = $item_mem->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($memories))->isIdenticalTo(1); + $this->assertCount(1, $memories); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Monitor.php b/phpunit/functional/Glpi/Inventory/Assets/MonitorTest.php similarity index 81% rename from tests/functional/Glpi/Inventory/Assets/Monitor.php rename to phpunit/functional/Glpi/Inventory/Assets/MonitorTest.php index 8338e9e1f87..96497481928 100644 --- a/tests/functional/Glpi/Inventory/Assets/Monitor.php +++ b/phpunit/functional/Glpi/Inventory/Assets/MonitorTest.php @@ -39,9 +39,9 @@ /* Test for inc/inventory/asset/monitor.class.php */ -class Monitor extends AbstractInventoryAsset +class MonitorTest extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -141,7 +141,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\Monitor($computer, $json->content->monitors); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -150,8 +150,10 @@ public function testHandle() //first, check there are no monitor linked to this computer $ico = new \Computer_Item(); - $this->boolean($ico->getFromDbByCrit(['computers_id' => $computer->fields['id'], 'itemtype' => 'Monitor'])) - ->isFalse('A monitor is already linked to computer!'); + $this->assertFalse( + $ico->getFromDbByCrit(['computers_id' => $computer->fields['id'], 'itemtype' => 'Monitor']), + 'A monitor is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -164,7 +166,7 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Monitor($computer, $json->content->monitors); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); $agent = new \Agent(); $agent->getEmpty(); @@ -173,8 +175,10 @@ public function testHandle() //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($ico->getFromDbByCrit(['computers_id' => $computer->fields['id'], 'itemtype' => 'Monitor'])) - ->isTrue('Monitor has not been linked to computer :('); + $this->assertTrue( + $ico->getFromDbByCrit(['computers_id' => $computer->fields['id'], 'itemtype' => 'Monitor']), + 'Monitor has not been linked to computer :(' + ); } public function testInventoryMove() @@ -219,27 +223,27 @@ public function testInventoryMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Sharp Corporation']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we have 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); - $this->integer(current($monitors)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $monitors); + $this->assertSame($manufacturers_id, current($monitors)['manufacturers_id']); //we have 1 monitor items linked to the computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //monitor present in the inventory source is dynamic $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //same inventory again $inventory = $this->doInventory($xml_source, true); @@ -254,19 +258,19 @@ public function testInventoryMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we still have only 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); - $this->integer(current($monitors)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $monitors); + $this->assertSame($manufacturers_id, current($monitors)['manufacturers_id']); //we still have only 1 monitor items linked to the computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //same monitor, but on another computer $xml_source_2 = " @@ -304,27 +308,27 @@ public function testInventoryMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_2_id = $inventory->getItem()->fields['id']; - $this->integer($computers_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_2_id); //we still have only 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); - $this->integer(current($monitors)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $monitors); + $this->assertSame($manufacturers_id, current($monitors)['manufacturers_id']); //no longer linked on first computer inventoried $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(0); + $this->assertCount(0, $monitors); //but now linked on last inventoried computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_2_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //monitor is still dynamic $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_2_id, 'is_dynamic' => 1]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //replay first computer inventory, monitor is back \o/ $inventory = $this->doInventory($xml_source, true); @@ -339,24 +343,24 @@ public function testInventoryMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //we still have only 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); - $this->integer(current($monitors)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $monitors); + $this->assertSame($manufacturers_id, current($monitors)['manufacturers_id']); //linked again on first computer inventoried $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //no longer linked on last inventoried computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_2_id]); - $this->integer(count($monitors))->isIdenticalTo(0); + $this->assertCount(0, $monitors); //monitor is still dynamic $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); } public function testInventoryNoMove() @@ -401,27 +405,27 @@ public function testInventoryNoMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Sharp Corporation']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we have 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); - $this->integer(current($monitors)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $monitors); + $this->assertSame($manufacturers_id, current($monitors)['manufacturers_id']); //we have 1 monitor items linked to the computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //monitor present in the inventory source is dynamic $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //same inventory again $inventory = $this->doInventory($xml_source, true); @@ -436,23 +440,23 @@ public function testInventoryNoMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we still have only 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); - $this->integer(current($monitors)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $monitors); + $this->assertSame($manufacturers_id, current($monitors)['manufacturers_id']); //we still have only 1 monitor items linked to the computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //set to global management - $this->boolean($monitor->getFromDB(current($monitors)['items_id'])); - $this->boolean($monitor->update(['id' => $monitor->fields['id'], 'is_global' => \Config::GLOBAL_MANAGEMENT])); + $this->assertTrue($monitor->getFromDB(current($monitors)['items_id'])); + $this->assertTrue($monitor->update(['id' => $monitor->fields['id'], 'is_global' => \Config::GLOBAL_MANAGEMENT])); //same monitor, but on another computer $xml_source_2 = " @@ -490,29 +494,29 @@ public function testInventoryNoMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_2_id = $inventory->getItem()->fields['id']; - $this->integer($computers_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_2_id); //we still have only 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); - $this->integer(current($monitors)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $monitors); + $this->assertSame($manufacturers_id, current($monitors)['manufacturers_id']); //still linked on first computer inventoried $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //also linked on last inventoried computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_2_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //monitor is still dynamic $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_2_id, 'is_dynamic' => 1]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); } public function testInventoryGlobalManagement() @@ -567,27 +571,27 @@ public function testInventoryGlobalManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Sharp Corporation']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we have 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); - $this->integer(current($monitors)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $monitors); + $this->assertSame($manufacturers_id, current($monitors)['manufacturers_id']); //we have 1 monitor items linked to the computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //monitor present in the inventory source is dynamic $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //same monitor, but on another computer $xml_source_2 = " @@ -635,29 +639,29 @@ public function testInventoryGlobalManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_2_id = $inventory->getItem()->fields['id']; - $this->integer($computers_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_2_id); //we still have only 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); - $this->integer(current($monitors)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $monitors); + $this->assertSame($manufacturers_id, current($monitors)['manufacturers_id']); //still linked on first computer inventoried $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //also linked on last inventoried computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_2_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //monitor is still dynamic $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_2_id, 'is_dynamic' => 1]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); } public function testInventoryUnitManagement() @@ -712,27 +716,27 @@ public function testInventoryUnitManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Sharp Corporation']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we have 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); - $this->integer(current($monitors)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $monitors); + $this->assertSame($manufacturers_id, current($monitors)['manufacturers_id']); //we have 1 monitor items linked to the computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //monitor present in the inventory source is dynamic $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //same inventory again $inventory = $this->doInventory($xml_source, true); @@ -747,23 +751,23 @@ public function testInventoryUnitManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we still have only 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); - $this->integer(current($monitors)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $monitors); + $this->assertSame($manufacturers_id, current($monitors)['manufacturers_id']); //we still have only 1 monitor items linked to the computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //set to global management - $this->boolean($monitor->getFromDB(current($monitors)['items_id'])); - $this->boolean($monitor->update(['id' => $monitor->fields['id'], 'is_global' => \Config::GLOBAL_MANAGEMENT])); + $this->assertTrue($monitor->getFromDB(current($monitors)['items_id'])); + $this->assertTrue($monitor->update(['id' => $monitor->fields['id'], 'is_global' => \Config::GLOBAL_MANAGEMENT])); //same monitor, but on another computer $xml_source_2 = " @@ -811,27 +815,27 @@ public function testInventoryUnitManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_2_id = $inventory->getItem()->fields['id']; - $this->integer($computers_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_2_id); //we still have only 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); - $this->integer(current($monitors)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $monitors); + $this->assertSame($manufacturers_id, current($monitors)['manufacturers_id']); //no longer linked on first computer inventoried $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(0); + $this->assertCount(0, $monitors); //but now linked on last inventoried computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_2_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //monitor is still dynamic $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_2_id, 'is_dynamic' => 1]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //change default configuration to unit management $this->login(); @@ -856,24 +860,24 @@ public function testInventoryUnitManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //we still have only 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); - $this->integer(current($monitors)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $monitors); + $this->assertSame($manufacturers_id, current($monitors)['manufacturers_id']); //linked again on first computer inventoried $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //no longer linked on last inventoried computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_2_id]); - $this->integer(count($monitors))->isIdenticalTo(0); + $this->assertCount(0, $monitors); //monitor is still dynamic $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); } public function testInventoryImportOrNot() @@ -908,11 +912,11 @@ public function testInventoryImportOrNot() //per default, configuration allows monitor import. change that. $this->login(); $conf = new \Glpi\Inventory\Conf(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'import_monitor' => 0 ]) - )->isTrue(); + ); $this->logout(); //computer inventory with one printer @@ -920,11 +924,11 @@ public function testInventoryImportOrNot() //restore default configuration $this->login(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'import_monitor' => 1 ]) - )->isTrue(); + ); $this->logOut(); //check for expected logs @@ -937,14 +941,14 @@ public function testInventoryImportOrNot() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //no monitor linked to the computer $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(0); + $this->assertCount(0, $monitors); //inventory again $this->doInventory($xml_source, true); @@ -959,19 +963,19 @@ public function testInventoryImportOrNot() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //we now have 1 monitor $monitors = $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //we have 1 monitor items linked to the computer $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); //monitor present in the inventory source is dynamic $monitors = $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($monitors))->isIdenticalTo(1); + $this->assertCount(1, $monitors); } public function testInventoryMonitorLog() @@ -1016,7 +1020,7 @@ public function testInventoryMonitorLog() //check computer $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //no log from first import (Computer or Monitor) $nblogsnow = countElementsInTable(\Log::getTable()); @@ -1031,14 +1035,14 @@ public function testInventoryMonitorLog() ] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //we have 2 monitor - $this->integer(count($monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]])))->isIdenticalTo(2); + $this->assertCount(2, $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]])); //we have 2 monitor items linked to the computer - $this->integer(count($item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id])))->isIdenticalTo(2); + $this->assertCount(2, $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id])); //we have 2 dynamic link - $this->integer(count($item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1])))->isIdenticalTo(2); + $this->assertCount(2, $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1])); $xml_source = " @@ -1074,14 +1078,14 @@ public function testInventoryMonitorLog() 'linked_action' => \Log::HISTORY_DEL_RELATION ] ]); - $this->integer(count($logs))->isIdenticalTo(1); + $this->assertCount(1, $logs); //we have 2 monitor - $this->integer(count($monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]])))->isIdenticalTo(2); + $this->assertCount(2, $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]])); //we have 1 monitor items linked to the computer - $this->integer(count($item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id])))->isIdenticalTo(1); + $this->assertCount(1, $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id])); //we have 1 dynamic link - $this->integer(count($item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1])))->isIdenticalTo(1); + $this->assertCount(1, $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1])); $xml_source = " @@ -1124,14 +1128,14 @@ public function testInventoryMonitorLog() 'linked_action' => \Log::HISTORY_ADD_RELATION ] ]); - $this->integer(count($logs))->isIdenticalTo(1); + $this->assertCount(1, $logs); //we have 2 monitor - $this->integer(count($monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]])))->isIdenticalTo(2); + $this->assertCount(2, $monitor->find(['NOT' => ['name' => ['LIKE', '_test_%']]])); //we have 2 monitor items linked to the computer - $this->integer(count($item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id])))->isIdenticalTo(2); + $this->assertCount(2, $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id])); //we have 2 dynamic link - $this->integer(count($item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1])))->isIdenticalTo(2); + $this->assertCount(2, $item_monitor->find(['itemtype' => 'Monitor', 'computers_id' => $computers_id, 'is_dynamic' => 1])); } public function testInventoryRemoved() @@ -1147,26 +1151,26 @@ public function testInventoryRemoved() //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('LF014-2017-02-20-12-19-56') - ->string['name']->isIdenticalTo('LF014-2017-02-20-12-19-56') - ->string['version']->isIdenticalTo('2.3.19') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['tag']->isIdenticalTo('000005') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']); + $this->assertIsArray($agent); + $this->assertSame('LF014-2017-02-20-12-19-56', $agent['deviceid']); + $this->assertSame('LF014-2017-02-20-12-19-56', $agent['name']); + $this->assertSame('2.3.19', $agent['version']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame('000005', $agent['tag']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check created monitor ++$nb_monitors; - $this->integer(countElementsInTable(\Monitor::getTable()))->isIdenticalTo($nb_monitors); - $this->integer(count($DB->request(['FROM' => \Computer_Item::getTable(), 'WHERE' => ['itemtype' => \Monitor::class, 'computers_id' => $computers_id]])))->isIdenticalTo(1); + $this->assertSame($nb_monitors, countElementsInTable(\Monitor::getTable())); + $this->assertCount(1, $DB->request(['FROM' => \Computer_Item::getTable(), 'WHERE' => ['itemtype' => \Monitor::class, 'computers_id' => $computers_id]])); //remove monitor $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_3.json')); @@ -1174,8 +1178,8 @@ public function testInventoryRemoved() $this->doInventory($json); //monitor is still present in database - $this->integer(countElementsInTable(\Monitor::getTable()))->isIdenticalTo($nb_monitors); + $this->assertSame($nb_monitors, countElementsInTable(\Monitor::getTable())); //link to monitor has been removed - $this->integer(count($DB->request(['FROM' => \Computer_Item::getTable(), 'WHERE' => ['itemtype' => \Monitor::class, 'computers_id' => $computers_id]])))->isIdenticalTo(0); + $this->assertCount(0, $DB->request(['FROM' => \Computer_Item::getTable(), 'WHERE' => ['itemtype' => \Monitor::class, 'computers_id' => $computers_id]])); } } diff --git a/tests/functional/Glpi/Inventory/Assets/NetworkCard.php b/phpunit/functional/Glpi/Inventory/Assets/NetworkCard.php similarity index 90% rename from tests/functional/Glpi/Inventory/Assets/NetworkCard.php rename to phpunit/functional/Glpi/Inventory/Assets/NetworkCard.php index a95033b2030..9ee8c244470 100644 --- a/tests/functional/Glpi/Inventory/Assets/NetworkCard.php +++ b/phpunit/functional/Glpi/Inventory/Assets/NetworkCard.php @@ -41,7 +41,7 @@ class NetworkCard extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -242,7 +242,7 @@ public function testPrepare($xml, $expected, $virtual) $conf = new \Glpi\Inventory\Conf(); $asset->checkConf($conf); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } /** @@ -259,17 +259,18 @@ public function testNoVirtuals($xml, $expected, $virtual) $asset->setExtraData((array)$json->content); $this->login(); $conf = new \Glpi\Inventory\Conf(); - $this->boolean($conf->saveConf(['component_networkcardvirtual' => 0]))->isTrue(); + $this->assertTrue($conf->saveConf(['component_networkcardvirtual' => 0])); $this->logOut(); $asset->checkConf($conf); $result = $asset->prepare(); $this->login(); - $this->boolean($conf->saveConf(['component_networkcardvirtual' => 1]))->isTrue(); + $this->assertTrue($conf->saveConf(['component_networkcardvirtual' => 1])); $this->logOut(); if ($virtual) { - $this->array($result)->isEmpty(); + $this->assertIsArray($result); + $this->assertEmpty($result); } else { - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } } @@ -279,8 +280,10 @@ public function testHandle() //first, check there are no controller linked to this computer $idn = new \Item_DeviceNetworkCard(); - $this->boolean($idn->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A network card is already linked to computer!'); + $this->assertFalse( + $idn->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A network card is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -295,13 +298,15 @@ public function testHandle() $conf = new \Glpi\Inventory\Conf(); $asset->checkConf($conf); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($idn->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Network card has not been linked to computer :('); + $this->assertTrue( + $idn->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Network card has not been linked to computer :(' + ); } public function testAllNetwork() @@ -708,8 +713,10 @@ public function testAllNetwork() //first, check there are no controller linked to this computer $idn = new \Item_DeviceNetworkCard(); - $this->boolean($idn->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A network card is already linked to computer!'); + $this->assertFalse( + $idn->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A network card is already linked to computer!' + ); //convert data $converter = new \Glpi\Inventory\Converter(); @@ -722,29 +729,30 @@ public function testAllNetwork() $asset->checkConf($conf); $result = $asset->prepare(); - $this->array($result)->isEmpty(); + $this->assertIsArray($result); + $this->assertEmpty($result); $ports = $asset->getNetworkPorts(); - $this->array($ports) - ->hasSize(5) - ->hasKey('lo-00:00:00:00:00:00') - ->hasKey('wlp58s0-44:85:00:2b:90:bc') - ->hasKey('virbr0-52:54:00:fa:20:0e') - ->hasKey('virbr0-nic-52:54:00:fa:20:0e') - ->hasKey('tun0-'); - - $this->array($ports['lo-00:00:00:00:00:00']->ipaddress) - ->contains('127.0.0.1') - ->contains('::1'); - - $this->array($ports['wlp58s0-44:85:00:2b:90:bc']->ipaddress) - ->contains('192.168.1.119') - ->contains('fe80::92a4:26c6:99dd:2d60'); - - //handle + $this->assertIsArray($ports); + $this->assertCount(5, $ports); + $this->assertArrayHasKey('lo-00:00:00:00:00:00', $ports); + $this->assertArrayHasKey('wlp58s0-44:85:00:2b:90:bc', $ports); + $this->assertArrayHasKey('virbr0-52:54:00:fa:20:0e', $ports); + $this->assertArrayHasKey('virbr0-nic-52:54:00:fa:20:0e', $ports); + $this->assertArrayHasKey('tun0-', $ports); + + $this->assertIsArray($ports['lo-00:00:00:00:00:00']->ipaddress); + $this->assertTrue(in_array('127.0.0.1', $ports['lo-00:00:00:00:00:00']->ipaddress)); + $this->assertTrue(in_array('::1', $ports['lo-00:00:00:00:00:00']->ipaddress)); + + $this->assertIsArray($ports['wlp58s0-44:85:00:2b:90:bc']->ipaddress); + $this->assertTrue(in_array('192.168.1.119', $ports['wlp58s0-44:85:00:2b:90:bc']->ipaddress)); + $this->assertTrue(in_array('fe80::92a4:26c6:99dd:2d60', $ports['wlp58s0-44:85:00:2b:90:bc']->ipaddress)); + + //handle $asset->handleLinks(); $asset->handle(); - //TODO: check for created values in database + //TODO: check for created values in database } public function testInventoryUpdate() @@ -819,13 +827,13 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $manufacturer = new \Manufacturer(); $manufacturers_id = $manufacturer->add([ 'name' => 'Intel Corporation' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $card_1_id = $device_net->add([ 'designation' => '82540EM Gigabit Ethernet Controller', @@ -833,7 +841,7 @@ public function testInventoryUpdate() 'mac_default' => '08:00:27:16:9C:60', 'entities_id' => 0 ]); - $this->integer($card_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $card_1_id); $item_card_1_id = $item_net->add([ 'items_id' => $computers_id, @@ -841,7 +849,7 @@ public function testInventoryUpdate() 'devicenetworkcards_id' => $card_1_id, 'mac' => '08:00:27:16:9C:60' ]); - $this->integer($item_card_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_card_1_id); $card_2_id = $device_net->add([ 'designation' => 'Ethernet Connection I219-LM', @@ -849,7 +857,7 @@ public function testInventoryUpdate() 'mac_default' => '18:db:f2:29:99:35', 'entities_id' => 0 ]); - $this->integer($card_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $card_2_id); $item_card_2_id = $item_net->add([ 'items_id' => $computers_id, @@ -857,7 +865,7 @@ public function testInventoryUpdate() 'devicenetworkcards_id' => $card_2_id, 'mac' => '18:db:f2:29:99:35' ]); - $this->integer($item_card_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_card_2_id); $card_3_id = $device_net->add([ 'designation' => 'Me Ethernet Controller', @@ -865,19 +873,19 @@ public function testInventoryUpdate() 'mac_default' => '00:b1:00:00:00', 'entities_id' => 0 ]); - $this->integer($card_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $card_3_id); $item_card_3_id = $item_net->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicenetworkcards_id' => $card_3_id ]); - $this->integer($item_card_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_card_3_id); $cards = $item_net->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($cards))->isIdenticalTo(3); + $this->assertCount(3, $cards); foreach ($cards as $card) { - $this->variable($card['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $card['is_dynamic']); } //computer inventory knows only 2 network cards @@ -885,29 +893,29 @@ public function testInventoryUpdate() //we still have 3 network cards $cards = $device_net->find(); - $this->integer(count($cards))->isIdenticalTo(3); + $this->assertCount(3, $cards); //we still have 3 network cards items linked to the computer $cards = $item_net->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($cards))->isIdenticalTo(3); + $this->assertCount(3, $cards); //network cards present in the inventory source are now dynamic $cards = $item_net->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($cards))->isIdenticalTo(2); + $this->assertCount(2, $cards); //network card not present in the inventory is still not dynamic $cards = $item_net->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($cards))->isIdenticalTo(1); + $this->assertCount(1, $cards); - $this->boolean( + $this->assertTrue( $network_port->getFromDBByCrit(['mac' => '08:00:27:16:9c:60']) - )->isTrue(); + ); // the port is up - $this->string($network_port->fields['ifinternalstatus'])->isEqualTo('1'); - $this->string($network_port->fields['ifstatus'])->isEqualTo('1'); + $this->assertEquals('1', $network_port->fields['ifinternalstatus']); + $this->assertEquals('1', $network_port->fields['ifstatus']); - //Redo inventory, but with removed last network card - //and the port on the first card is down + //Redo inventory, but with removed last network card + //and the port on the first card is down $xml_source = " @@ -949,26 +957,26 @@ public function testInventoryUpdate() //we still have 3 network cards $cards = $device_net->find(); - $this->integer(count($cards))->isIdenticalTo(3); + $this->assertCount(3, $cards); //we now have 2 network cards linked to computer only $cards = $item_net->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($cards))->isIdenticalTo(2); + $this->assertCount(2, $cards); //network card present in the inventory source is still dynamic $cards = $item_net->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($cards))->isIdenticalTo(1); + $this->assertCount(1, $cards); //network card not present in the inventory is still not dynamic $cards = $item_net->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($cards))->isIdenticalTo(1); + $this->assertCount(1, $cards); - $this->boolean( + $this->assertTrue( $network_port->getFromDBByCrit(['mac' => '08:00:27:16:9c:60']) - )->isTrue(); + ); // the port is up - $this->string($network_port->fields['ifinternalstatus'])->isEqualTo('1'); + $this->assertEquals('1', $network_port->fields['ifinternalstatus']); // but the connection is down - $this->string($network_port->fields['ifstatus'])->isEqualTo('2'); + $this->assertEquals('2', $network_port->fields['ifstatus']); } } diff --git a/tests/functional/Glpi/Inventory/Assets/NetworkEquipment.php b/phpunit/functional/Glpi/Inventory/Assets/NetworkEquipmentTest.php similarity index 85% rename from tests/functional/Glpi/Inventory/Assets/NetworkEquipment.php rename to phpunit/functional/Glpi/Inventory/Assets/NetworkEquipmentTest.php index 4f427d95665..2043c610a8f 100644 --- a/tests/functional/Glpi/Inventory/Assets/NetworkEquipment.php +++ b/phpunit/functional/Glpi/Inventory/Assets/NetworkEquipmentTest.php @@ -39,11 +39,11 @@ /* Test for inc/inventory/asset/networkequipment.class.php */ -class NetworkEquipment extends AbstractInventoryAsset +class NetworkEquipmentTest extends AbstractInventoryAsset { const INV_FIXTURES = GLPI_ROOT . '/vendor/glpi-project/inventory_format/examples/'; - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -175,7 +175,7 @@ public function testPrepare($xml, $asset) $main = new \Glpi\Inventory\Asset\NetworkEquipment($netequ, $json); $main->setExtraData((array)$json->content); $result = $main->prepare(); - $this->object($result[0])->isEqualTo(json_decode($asset)); + $this->assertEquals(json_decode($asset), $result[0]); } public function testStacked() @@ -188,19 +188,19 @@ public function testStacked() $data = (array)$json->content; $inventory = new \Glpi\Inventory\Inventory(); - $this->boolean($inventory->setData($json))->isTrue(); + $this->assertTrue($inventory->setData($json)); $agent = new \Agent(); - $this->integer($agent->handleAgent($inventory->extractMetadata()))->isIdenticalTo(0); + $this->assertSame(0, $agent->handleAgent($inventory->extractMetadata())); $main = new \Glpi\Inventory\Asset\NetworkEquipment($netequ, $json); $main->setAgent($agent)->setExtraData($data); $result = $main->prepare(); - $this->array($result)->hasSize(1); + $this->assertCount(1, $result); - $this->boolean($main->isStackedSwitch())->isFalse(); + $this->assertFalse($main->isStackedSwitch()); - //stacked + //stacked $json_str = file_get_contents(self::INV_FIXTURES . 'networkequipment_2.json'); $json = json_decode($json_str); @@ -208,15 +208,15 @@ public function testStacked() $data = (array)$json->content; $inventory = new \Glpi\Inventory\Inventory(); - $this->boolean($inventory->setData($json))->isTrue(); + $this->assertTrue($inventory->setData($json)); $agent = new \Agent(); - $this->integer($agent->handleAgent($inventory->extractMetadata()))->isIdenticalTo(0); + $this->assertSame(0, $agent->handleAgent($inventory->extractMetadata())); $main = new \Glpi\Inventory\Asset\NetworkEquipment($netequ, $json); $main->setAgent($agent)->setExtraData($data); $result = $main->prepare(); - $this->array($result)->hasSize(5); + $this->assertCount(5, $result); $expected_stack = [ 1001 => [ @@ -281,11 +281,11 @@ public function testStacked() ] ]; - $this->boolean($main->isStackedSwitch())->isTrue(); + $this->assertTrue($main->isStackedSwitch()); $stack = $main->getStackedSwitches(); - $this->array(array_keys($expected_stack))->isIdenticalTo(array_keys($stack)); + $this->assertSame(array_keys($stack), array_keys($expected_stack)); foreach ($expected_stack as $key => $entry) { - $this->array($entry)->isIdenticalTo((array)$stack[$key]); + $this->assertSame((array)$stack[$key], $entry); } } @@ -380,26 +380,28 @@ public function testStackedDellSwitch() var_dump($error); } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); $networkEquipment = new \NetworkEquipment(); $networkPort = new \NetworkPort(); - $this->integer(countElementsInTable($networkPort->getTable()))->isIdenticalTo(2, 'Must have two ports'); + $this->assertSame(2, countElementsInTable($networkPort->getTable()), 'Must have two ports'); foreach ([['DL253300100', 177783810], ['DL253300200', 242009090]] as list($serial, $logical_number)) { - $this->boolean( - $networkEquipment->getFromDBByCrit(['serial' => $serial]) - )->isTrue("Switch s/n $serial doesn't exist"); + $this->assertTrue( + $networkEquipment->getFromDBByCrit(['serial' => $serial]), + "Switch s/n $serial doesn't exist" + ); - $this->boolean( + $this->assertTrue( $networkPort->getFromDBByCrit([ 'itemtype' => $networkEquipment->getType(), 'items_id' => $networkEquipment->getID(), 'logical_number' => $logical_number - ]) - )->isTrue(sprintf("Switch \"%s\" doesn't have port with ifindex %d", $networkEquipment->fields['name'], $logical_number)); + ]), + sprintf("Switch \"%s\" doesn't have port with ifindex %d", $networkEquipment->fields['name'], $logical_number) + ); } } @@ -412,21 +414,21 @@ public function testHandle() $data = (array)$json->content; $inventory = new \Glpi\Inventory\Inventory(); - $this->boolean($inventory->setData($json))->isTrue(); + $this->assertTrue($inventory->setData($json)); $agent = new \Agent(); - $this->integer($agent->handleAgent($inventory->extractMetadata()))->isIdenticalTo(0); + $this->assertSame(0, $agent->handleAgent($inventory->extractMetadata())); $main = new \Glpi\Inventory\Asset\NetworkEquipment($netequ, $json); $main->setAgent($agent)->setExtraData($data); $main->checkConf(new \Glpi\Inventory\Conf()); $result = $main->prepare(); - $this->array($result)->hasSize(5); + $this->assertCount(5, $result); - $this->boolean($main->isStackedSwitch())->isTrue(); + $this->assertTrue($main->isStackedSwitch()); $main->handle(); - $this->boolean($main->areLinksHandled())->isTrue(); + $this->assertTrue($main->areLinksHandled()); } /** @@ -477,7 +479,7 @@ public function testNortelSwitch() 'name' => 'otherswitch', 'entities_id' => 0 ]); - $this->integer($networkequipments_other_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkequipments_other_id); $networkports_other_id = $networkport->add([ 'itemtype' => 'NetworkEquipment', @@ -486,7 +488,7 @@ public function testNortelSwitch() 'mac' => '00:24:b5:bd:c8:01', 'logical_number' => 22 ]); - $this->integer($networkports_other_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkports_other_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -500,16 +502,16 @@ public function testNortelSwitch() var_dump($error); } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); $links = getAllDataFromTable('glpi_networkports_networkports'); - $this->integer(count($links))->isIdenticalTo(1, 'May have 1 connection between 2 network ports'); + $this->assertCount(1, $links, 'May have 1 connection between 2 network ports'); $link = current($links); - $this->integer($link['networkports_id_2'])->isIdenticalTo($networkports_other_id, 'Must be linked to otherswitch port'); + $this->assertSame($networkports_other_id, $link['networkports_id_2'], 'Must be linked to otherswitch port'); $a_networkports = getAllDataFromTable('glpi_networkports'); - $this->integer(count($a_networkports))->isIdenticalTo(2, 'May have 2 network ports (' . print_r($a_networkports, true) . ')'); + $this->assertCount(2, $a_networkports, 'May have 2 network ports (' . print_r($a_networkports, true) . ')'); } /** @@ -560,7 +562,7 @@ public function testNortelUnmanaged() 'name' => 'Unmanaged device', 'entities_id' => 0 ]); - $this->integer($unmanageds_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $unmanageds_id); $unmanaged_networkports_id = $networkport->add([ 'itemtype' => 'Unmanaged', @@ -569,7 +571,7 @@ public function testNortelUnmanaged() 'mac' => '00:24:b5:bd:c8:01', 'logical_number' => 22 ]); - $this->integer($unmanaged_networkports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $unmanaged_networkports_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -583,16 +585,16 @@ public function testNortelUnmanaged() var_dump($error); } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); $links = getAllDataFromTable('glpi_networkports_networkports'); - $this->integer(count($links))->isIdenticalTo(1, 'May have 1 connection between 2 network ports'); + $this->assertCount(1, $links, 'May have 1 connection between 2 network ports'); $link = current($links); - $this->integer($link['networkports_id_2'])->isIdenticalTo($unmanaged_networkports_id, 'Must be linked to Unmanaged device port'); + $this->assertSame($unmanaged_networkports_id, $link['networkports_id_2'], 'Must be linked to Unmanaged device port'); $a_networkports = getAllDataFromTable('glpi_networkports'); - $this->integer(count($a_networkports))->isIdenticalTo(2, 'May have 2 network ports (' . print_r($a_networkports, true) . ')'); + $this->assertCount(2, $a_networkports, 'May have 2 network ports (' . print_r($a_networkports, true) . ')'); } /** @@ -647,21 +649,21 @@ public function testNortelNodevice() var_dump($error); } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); $links = getAllDataFromTable('glpi_networkports_networkports'); - $this->integer(count($links))->isIdenticalTo(1, 'May have 1 connection between 2 network ports'); + $this->assertCount(1, $links, 'May have 1 connection between 2 network ports'); $link = current($links); $netport = new \NetworkPort(); - $this->boolean($netport->getFromDBByCrit(['mac' => '00:24:b5:bd:c8:01']))->isTrue(); - $this->integer($link['networkports_id_2'])->isIdenticalTo($netport->fields['id'], 'Must be linked to new Unmanaged device port'); + $this->assertTrue($netport->getFromDBByCrit(['mac' => '00:24:b5:bd:c8:01'])); + $this->assertSame($netport->fields['id'], $link['networkports_id_2'], 'Must be linked to new Unmanaged device port'); $a_networkports = getAllDataFromTable('glpi_networkports'); - $this->integer(count($a_networkports))->isIdenticalTo(2, 'May have 2 network ports (' . print_r($a_networkports, true) . ')'); + $this->assertCount(2, $a_networkports, 'May have 2 network ports (' . print_r($a_networkports, true) . ')'); $unmanageds = getAllDataFromTable(\Unmanaged::getTable()); - $this->integer(count($unmanageds))->isIdenticalTo(1, 'May have 1 new unmanaged device'); + $this->assertCount(1, $unmanageds, 'May have 1 new unmanaged device'); } /** @@ -714,7 +716,7 @@ public function testCisco1Switch() 'name' => 'otherswitch', 'entities_id' => 0 ]); - $this->integer($networkequipments_other_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkequipments_other_id); // Management port $managementports_id = $networkport->add([ @@ -723,14 +725,14 @@ public function testCisco1Switch() 'items_id' => $networkequipments_other_id, 'entities_id' => 0 ]); - $this->integer($managementports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $managementports_id); $networknames_id = $networkName->add([ 'entities_id' => 0, 'itemtype' => 'NetworkPort', 'items_id' => $managementports_id ]); - $this->integer($networknames_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networknames_id); $ipaddress_id = $iPAddress->add([ 'entities_id' => 0, @@ -738,7 +740,7 @@ public function testCisco1Switch() 'items_id' => $networknames_id, 'name' => '192.168.200.124' ]); - $this->integer($ipaddress_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ipaddress_id); // Port GigabitEthernet0/10 $networkports_other_id = $networkport->add([ @@ -749,7 +751,7 @@ public function testCisco1Switch() 'logical_number' => 22, 'ifdescr' => 'GigabitEthernet0/10' ]); - $this->integer($networkports_other_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkports_other_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -763,17 +765,17 @@ public function testCisco1Switch() var_dump($error); } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); $a_portslinks = getAllDataFromTable('glpi_networkports_networkports'); - $this->integer(count($a_portslinks))->isIdenticalTo(1, sprintf('May have 1 connection between 2 network ports, %s found', count($a_portslinks))); + $this->assertCount(1, $a_portslinks, sprintf('May have 1 connection between 2 network ports, %s found', count($a_portslinks))); $a_networkports = getAllDataFromTable('glpi_networkports'); - $this->integer(count($a_networkports))->isIdenticalTo(3, 'May have 3 network ports (' . print_r($a_networkports, true) . ')'); + $this->assertCount(3, $a_networkports, 'May have 3 network ports (' . print_r($a_networkports, true) . ')'); $portLink = current($a_portslinks); - $this->integer($portLink['networkports_id_2'])->isIdenticalTo($networkports_other_id); + $this->assertSame($networkports_other_id, $portLink['networkports_id_2']); } /** @@ -828,21 +830,21 @@ public function testCisco1Unmanaged() 'name' => 'otherswitch', 'entities_id' => 0 ]); - $this->integer($unmanageds_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $unmanageds_id); $networkports_unknown_id = $networkport->add([ 'itemtype' => 'Unmanaged', 'items_id' => $unmanageds_id, 'entities_id' => 0 ]); - $this->integer($networkports_unknown_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkports_unknown_id); $networknames_id = $networkName->add([ 'entities_id' => 0, 'itemtype' => 'NetworkPort', 'items_id' => $networkports_unknown_id ]); - $this->integer($networknames_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networknames_id); $ipaddress_id = $iPAddress->add([ 'entities_id' => 0, @@ -850,7 +852,7 @@ public function testCisco1Unmanaged() 'items_id' => $networknames_id, 'name' => '192.168.200.124' ]); - $this->integer($ipaddress_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ipaddress_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -864,18 +866,18 @@ public function testCisco1Unmanaged() var_dump($error); } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); $a_portslinks = getAllDataFromTable('glpi_networkports_networkports'); - $this->integer(count($a_portslinks))->isIdenticalTo(1, 'May have 1 connection between 2 network ports'); + $this->assertCount(1, $a_portslinks, 'May have 1 connection between 2 network ports'); $a_networkports = getAllDataFromTable('glpi_networkports'); - $this->integer(count($a_networkports))->isIdenticalTo(3, 'May have 3 network ports (' . print_r($a_networkports, true) . ')'); + $this->assertCount(3, $a_networkports, 'May have 3 network ports (' . print_r($a_networkports, true) . ')'); //FIXME: does not work :'( //$a_unknowns = getAllDataFromTable('glpi_unmanageds'); - //$this->integer(count($a_unknowns))->isIdenticalTo(1, 'May have only one unknown device (' . print_r($a_unknowns, true) . ')'); + //$this->assertCount(1, $a_unknowns, 'May have only one unknown device (' . print_r($a_unknowns, true) . ')'); $a_networkport_ref = [ 'items_id' => $unmanageds_id, @@ -906,7 +908,7 @@ public function testCisco1Unmanaged() 'lastup' => null ]; $networkport = new \NetworkPort(); - $this->boolean($networkport->getFromDBByCrit(['name' => 'GigabitEthernet0/10']))->isTrue(); + $this->assertTrue($networkport->getFromDBByCrit(['name' => 'GigabitEthernet0/10'])); unset( $networkport->fields['id'], $networkport->fields['date_mod'], @@ -914,10 +916,10 @@ public function testCisco1Unmanaged() ); //FIXME: does not work :'( - /*$this->array($networkport->fields)->isEqualTo($a_networkport_ref, 'New unknown port created'); + /*$this->assertEquals($a_networkport_ref, $networkport->fields, 'New unknown port created'); $portLink = current($a_portslinks); - $this->integer($a_portslinks['networkports_id_2'])->isIdenticalTo($networkports_unknown_id);*/ + $this->assertSame($networkports_unknown_id, $a_portslinks['networkports_id_2']);*/ } public function testCisco1Nodevice() @@ -969,20 +971,20 @@ public function testCisco1Nodevice() var_dump($error); } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); $a_portslinks = getAllDataFromTable('glpi_networkports_networkports'); - $this->integer(count($a_portslinks))->isIdenticalTo(1, 'May have 1 connection between 2 network ports'); + $this->assertCount(1, $a_portslinks, 'May have 1 connection between 2 network ports'); $a_networkports = getAllDataFromTable('glpi_networkports'); - $this->integer(count($a_networkports))->isIdenticalTo(2, 'May have 2 network ports (' . print_r($a_networkports, true) . ')'); + $this->assertCount(2, $a_networkports, 'May have 2 network ports (' . print_r($a_networkports, true) . ')'); $networkPort = new \NetworkPort(); $networkPort->getFromDBByCrit(['name' => 'GigabitEthernet0/10']); $portLink = current($a_portslinks); - $this->integer($portLink['networkports_id_2'])->isIdenticalTo($networkPort->fields['id']); + $this->assertSame($networkPort->fields['id'], $portLink['networkports_id_2']); } /** @@ -1036,7 +1038,7 @@ public function testCisco2Switch() 'name' => 'juniperswitch3', 'entities_id' => 0 ]); - $this->integer($networkequipments_other_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkequipments_other_id); // Port ge-0/0/1.0 $networkports_other_id = $networkport->add([ @@ -1047,7 +1049,7 @@ public function testCisco2Switch() 'logical_number' => 504, 'ifdescr' => 'ge-0/0/1.0' ]); - $this->integer($networkports_other_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkports_other_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -1061,18 +1063,18 @@ public function testCisco2Switch() var_dump($error); } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); $a_portslinks = getAllDataFromTable('glpi_networkports_networkports'); - $this->integer(count($a_portslinks))->isIdenticalTo(1, 'May have 1 connection between 2 network ports'); + $this->assertCount(1, $a_portslinks, 'May have 1 connection between 2 network ports'); $a_networkports = getAllDataFromTable('glpi_networkports'); - $this->integer(count($a_networkports))->isIdenticalTo(2, 'May have 2 network ports (' . print_r($a_networkports, true) . ')'); + $this->assertCount(2, $a_networkports, 'May have 2 network ports (' . print_r($a_networkports, true) . ')'); //FIXME: does not work :'( /*$portLink = current($a_portslinks); - $this->integer($portLink['networkports_id_2'])->isIdenticalTo($networkequipments_other_id);*/ + $this->assertSame($networkequipments_other_id, $portLink['networkports_id_2']);*/ } public function testSwitchLldpImport() @@ -1144,7 +1146,7 @@ public function testSwitchLldpImport() 'entities_id' => 0, 'name' => 'juniperswitch3', ]); - $this->integer($networkEquipments_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkEquipments_id); // Add management port // 2c:6b:f5:98:f9:70 @@ -1155,7 +1157,7 @@ public function testSwitchLldpImport() 'instantiation_type' => 'NetworkPortAggregate', 'name' => 'general', ]); - $this->integer($mngtports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $mngtports_id); $ports_id = $networkPort->add([ 'mac' => '2c:6b:f5:98:f9:71', @@ -1166,7 +1168,7 @@ public function testSwitchLldpImport() 'itemtype' => 'NetworkEquipment', 'ifdescr' => 'ge-0/0/1.0', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -1180,12 +1182,12 @@ public function testSwitchLldpImport() var_dump($error); } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); // check port - $this->boolean($networkPort->getFromDBByCrit(['mac' => 'b4:39:d6:3b:22:bd']))->isTrue(); - $this->boolean($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id']))->isTrue(); + $this->assertTrue($networkPort->getFromDBByCrit(['mac' => 'b4:39:d6:3b:22:bd'])); + $this->assertTrue($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id'])); } /** @@ -1257,7 +1259,7 @@ public function testSwitchLLDPImport_ifdescr_ip_case1() 'entities_id' => 0, 'name' => 'sw10', ]); - $this->integer($networkEquipments_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkEquipments_id); // Add management port $mngtports_id = $networkPort->add([ @@ -1273,7 +1275,7 @@ public function testSwitchLLDPImport_ifdescr_ip_case1() ], ]); - $this->integer($mngtports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $mngtports_id); // Add a port that will not be used, but needed for the test $ports_id = $networkPort->add([ @@ -1285,7 +1287,7 @@ public function testSwitchLLDPImport_ifdescr_ip_case1() 'itemtype' => 'NetworkEquipment', 'ifdescr' => '27', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Add the second port right $ports_id = $networkPort->add([ @@ -1297,7 +1299,7 @@ public function testSwitchLLDPImport_ifdescr_ip_case1() 'itemtype' => 'NetworkEquipment', 'ifdescr' => '28', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Add another port that will not be used, but needed for the test $ports_id = $networkPort->add([ @@ -1309,7 +1311,7 @@ public function testSwitchLLDPImport_ifdescr_ip_case1() 'itemtype' => 'NetworkEquipment', 'ifdescr' => '29', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -1323,12 +1325,12 @@ public function testSwitchLLDPImport_ifdescr_ip_case1() var_dump($error); } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); // check port - $this->boolean($networkPort->getFromDBByCrit(['name' => 'port28']))->isTrue(); - $this->boolean($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id']))->isTrue(); + $this->assertTrue($networkPort->getFromDBByCrit(['name' => 'port28'])); + $this->assertTrue($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id'])); } /** @@ -1400,7 +1402,7 @@ public function testSwitchLLDPImport_ifdescr_ip_case2() 'entities_id' => 0, 'name' => 'sw10', ]); - $this->integer($networkEquipments_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkEquipments_id); // Add a port that will not be used, but needed for the test $ports_id = $networkPort->add([ @@ -1418,7 +1420,7 @@ public function testSwitchLLDPImport_ifdescr_ip_case2() ], 'ifdescr' => '27', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Add the second port right $ports_id = $networkPort->add([ @@ -1436,7 +1438,7 @@ public function testSwitchLLDPImport_ifdescr_ip_case2() ], 'ifdescr' => '28', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Add another port that will not be used, but needed for the test $ports_id = $networkPort->add([ @@ -1454,7 +1456,7 @@ public function testSwitchLLDPImport_ifdescr_ip_case2() ], 'ifdescr' => '29', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -1468,12 +1470,12 @@ public function testSwitchLLDPImport_ifdescr_ip_case2() var_dump($error); } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); // check port - $this->boolean($networkPort->getFromDBByCrit(['name' => 'port28'])); - $this->boolean($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id']))->isTrue(); + $this->assertTrue($networkPort->getFromDBByCrit(['name' => 'port28'])); + $this->assertTrue($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id'])); } /** @@ -1545,7 +1547,7 @@ public function testSwitchLLDPImport_ifnumber_mac_case1() 'entities_id' => 0, 'name' => 'sw10', ]); - $this->integer($networkEquipments_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkEquipments_id); // Add management port $mngtports_id = $networkPort->add([ @@ -1555,7 +1557,7 @@ public function testSwitchLLDPImport_ifnumber_mac_case1() 'name' => 'general', 'mac' => '00:24:b5:bd:c8:01', ]); - $this->integer($mngtports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $mngtports_id); // Add a port that will not be used, but needed for the test $ports_id = $networkPort->add([ @@ -1567,7 +1569,7 @@ public function testSwitchLLDPImport_ifnumber_mac_case1() 'ifdescr' => '20', 'mac' => '00:24:b5:bd:c8:02', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Add the second port right $ports_id = $networkPort->add([ @@ -1579,7 +1581,7 @@ public function testSwitchLLDPImport_ifnumber_mac_case1() 'ifdescr' => '21', 'mac' => '00:24:b5:bd:c8:03', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Add another port that will not be used, but needed for the test $ports_id = $networkPort->add([ @@ -1591,7 +1593,7 @@ public function testSwitchLLDPImport_ifnumber_mac_case1() 'ifdescr' => '22', 'mac' => '00:24:b5:bd:c8:04', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -1606,12 +1608,12 @@ public function testSwitchLLDPImport_ifnumber_mac_case1() } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); // check port - $this->boolean($networkPort->getFromDBByCrit(['name' => 'port21'])); - $this->boolean($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id']))->isTrue(); + $this->assertTrue($networkPort->getFromDBByCrit(['name' => 'port21'])); + $this->assertTrue($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id'])); } /** @@ -1683,7 +1685,7 @@ public function testSwitchLLDPImport_ifnumber_mac_case2() 'entities_id' => 0, 'name' => 'sw10', ]); - $this->integer($networkEquipments_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkEquipments_id); // Add a port that will not be used, but needed for the test $ports_id = $networkPort->add([ @@ -1695,7 +1697,7 @@ public function testSwitchLLDPImport_ifnumber_mac_case2() 'itemtype' => 'NetworkEquipment', 'ifdescr' => '20', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Add the second port right $ports_id = $networkPort->add([ @@ -1707,7 +1709,7 @@ public function testSwitchLLDPImport_ifnumber_mac_case2() 'itemtype' => 'NetworkEquipment', 'ifdescr' => '21', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Add another port that will not be used, but needed for the test $ports_id = $networkPort->add([ @@ -1719,7 +1721,7 @@ public function testSwitchLLDPImport_ifnumber_mac_case2() 'itemtype' => 'NetworkEquipment', 'ifdescr' => '22', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -1734,12 +1736,12 @@ public function testSwitchLLDPImport_ifnumber_mac_case2() } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); // check port - $this->boolean($networkPort->getFromDBByCrit(['name' => 'port21'])); - $this->boolean($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id']))->isTrue(); + $this->assertTrue($networkPort->getFromDBByCrit(['name' => 'port21'])); + $this->assertTrue($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id'])); } /** @@ -1811,7 +1813,7 @@ public function testSwitchLLDPImport_ifnumber_mac_case3() 'entities_id' => 0, 'name' => 'sw10', ]); - $this->integer($networkEquipments_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkEquipments_id); // Add a port that will not be used, but needed for the test $ports_id = $networkPort->add([ @@ -1823,7 +1825,7 @@ public function testSwitchLLDPImport_ifnumber_mac_case3() 'itemtype' => 'NetworkEquipment', 'ifdescr' => '20', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Add the second port right $ports_id = $networkPort->add([ @@ -1835,7 +1837,7 @@ public function testSwitchLLDPImport_ifnumber_mac_case3() 'itemtype' => 'NetworkEquipment', 'ifdescr' => '21', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Add another port that will not be used, but needed for the test $ports_id = $networkPort->add([ @@ -1847,7 +1849,7 @@ public function testSwitchLLDPImport_ifnumber_mac_case3() 'itemtype' => 'NetworkEquipment', 'ifdescr' => '22', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -1856,12 +1858,12 @@ public function testSwitchLLDPImport_ifnumber_mac_case3() $inventory = new \Glpi\Inventory\Inventory($data); $CFG_GLPI["is_contact_autoupdate"] = 1; //reset to default - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); // check port - $this->boolean($networkPort->getFromDBByCrit(['name' => 'port21'])); - $this->boolean($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id']))->isTrue(); + $this->assertTrue($networkPort->getFromDBByCrit(['name' => 'port21'])); + $this->assertTrue($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id'])); } public function testSwitchLLDPImport_othercase1() @@ -1933,7 +1935,7 @@ public function testSwitchLLDPImport_othercase1() 'entities_id' => 0, 'name' => 'sw001', ]); - $this->integer($networkEquipments_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkEquipments_id); // Add management port $mngtports_id = $networkPort->add([ @@ -1948,7 +1950,7 @@ public function testSwitchLLDPImport_othercase1() '-1' => '172.16.100.252' ], ]); - $this->integer($mngtports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $mngtports_id); // Add a port that will not be used, but needed for the test $ports_id = $networkPort->add([ @@ -1959,7 +1961,7 @@ public function testSwitchLLDPImport_othercase1() 'itemtype' => 'NetworkEquipment', 'ifdescr' => '47', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Add the second port right $ports_id = $networkPort->add([ @@ -1970,7 +1972,7 @@ public function testSwitchLLDPImport_othercase1() 'itemtype' => 'NetworkEquipment', 'ifdescr' => '48', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Add another port that will not be used, but needed for the test $ports_id = $networkPort->add([ @@ -1981,7 +1983,7 @@ public function testSwitchLLDPImport_othercase1() 'itemtype' => 'NetworkEquipment', 'ifdescr' => '49', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -1991,12 +1993,12 @@ public function testSwitchLLDPImport_othercase1() $inventory = new \Glpi\Inventory\Inventory($data); $CFG_GLPI["is_contact_autoupdate"] = 1; //reset to default - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); // check port - $this->boolean($networkPort->getFromDBByCrit(['name' => 'port48'])); - $this->boolean($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id']))->isTrue(); + $this->assertTrue($networkPort->getFromDBByCrit(['name' => 'port48'])); + $this->assertTrue($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id'])); } public function testSysdescr() @@ -2045,15 +2047,15 @@ public function testSysdescr() $data = json_decode($converter->convert($xml_source)); $inventory = new \Glpi\Inventory\Inventory($data); - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); // check sysdescr $networkequipement = new \NetworkEquipment(); $found_np = $networkequipement->find(['name' => "ucs6248up-cluster-pa3-B"]); - $this->integer(count($found_np))->isIdenticalTo(1); + $this->assertCount(1, $found_np); $first_np = array_pop($found_np); - $this->string($first_np['sysdescr'])->isIdenticalTo("this a sysdescr"); + $this->assertSame("this a sysdescr", $first_np['sysdescr']); $xml_source = " @@ -2099,15 +2101,15 @@ public function testSysdescr() $data = json_decode($converter->convert($xml_source)); $inventory = new \Glpi\Inventory\Inventory($data); - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); // check sysdescr $networkequipement = new \NetworkEquipment(); $found_np = $networkequipement->find(['name' => "ucs6248up-cluster-pa3-B"]); - $this->integer(count($found_np))->isIdenticalTo(1); + $this->assertCount(1, $found_np); $first_np = array_pop($found_np); - $this->string($first_np['sysdescr'])->isIdenticalTo("this a updated sysdescr"); + $this->assertSame("this a updated sysdescr", $first_np['sysdescr']); } public function testSwitchMacConnection1() @@ -2176,7 +2178,7 @@ public function testSwitchMacConnection1() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); // Add some computer ports $ports_id = $networkPort->add([ @@ -2187,7 +2189,7 @@ public function testSwitchMacConnection1() 'itemtype' => 'Computer', 'mac' => 'bc:97:e1:5c:0e:90', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); $ports_id = $networkPort->add([ 'name' => 'eth1', @@ -2197,7 +2199,7 @@ public function testSwitchMacConnection1() 'itemtype' => 'Computer', 'mac' => 'bc:97:e1:5c:0e:91', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -2207,13 +2209,13 @@ public function testSwitchMacConnection1() $inventory = new \Glpi\Inventory\Inventory($data); $CFG_GLPI["is_contact_autoupdate"] = 1; //reset to default - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); // Verify that eth0 is the only port connected - $this->integer(countElementsInTable($networkPort_NetworkPort->getTable()))->isIdenticalTo(1); - $this->boolean($networkPort->getFromDBByCrit(['name' => 'eth0'])); - $this->boolean($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id']))->isTrue(); + $this->assertSame(1, countElementsInTable($networkPort_NetworkPort->getTable())); + $this->assertTrue($networkPort->getFromDBByCrit(['name' => 'eth0'])); + $this->assertTrue($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id'])); } public function testSwitchMacConnection2() @@ -2279,11 +2281,11 @@ public function testSwitchMacConnection2() $computer = getItemByTypeName('Computer', '_test_pc01'); $computers_id = $computer->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $printer = getItemByTypeName('Printer', '_test_printer_ent0'); $printers_id = $printer->fields['id']; - $this->integer($printers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $printers_id); // Add some ports $ports_id = $networkPort->add([ @@ -2294,7 +2296,7 @@ public function testSwitchMacConnection2() 'itemtype' => $computer->getTypeName(1), 'mac' => 'bc:97:e1:5c:0e:90', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); $ports_id = $networkPort->add([ 'name' => 'eth1', @@ -2304,7 +2306,7 @@ public function testSwitchMacConnection2() 'itemtype' => $computer->getTypeName(1), 'mac' => 'bc:97:e1:5c:0e:91', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); $ports_id = $networkPort->add([ 'name' => 'internal', @@ -2314,10 +2316,10 @@ public function testSwitchMacConnection2() 'itemtype' => $printer->getTypeName(1), 'mac' => '00:85:eb:f4:be:20', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Make sure there are no hubs yet - $this->integer(countElementsInTable($unmanaged->getTable()))->isIdenticalTo(0); + $this->assertSame(0, countElementsInTable($unmanaged->getTable())); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -2327,15 +2329,15 @@ public function testSwitchMacConnection2() $inventory = new \Glpi\Inventory\Inventory($data); $CFG_GLPI["is_contact_autoupdate"] = 1; //reset to default - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); // Verify that gi0/3, eth0, internal ports are connected to a hub - $this->integer(countElementsInTable($unmanaged->getTable()))->isIdenticalTo(1); - $this->integer(countElementsInTable($networkPort_NetworkPort->getTable()))->isIdenticalTo(3); + $this->assertSame(1, countElementsInTable($unmanaged->getTable())); + $this->assertSame(3, countElementsInTable($networkPort_NetworkPort->getTable())); foreach (['gi0/3', 'eth0', 'internal'] as $port_name) { - $this->boolean($networkPort->getFromDBByCrit(['name' => $port_name])); - $this->boolean($networkPort->isHubConnected($networkPort->fields['id']))->isTrue(); + $this->assertTrue($networkPort->getFromDBByCrit(['name' => $port_name])); + $this->assertTrue($networkPort->isHubConnected($networkPort->fields['id'])); } } @@ -2401,7 +2403,7 @@ public function testSwitchMacConnection3() $computer = getItemByTypeName('Computer', '_test_pc01'); $computers_id = $computer->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); // Add some ports $ports_id = $networkPort->add([ @@ -2412,7 +2414,7 @@ public function testSwitchMacConnection3() 'itemtype' => $computer->getTypeName(1), 'mac' => 'bc:97:e1:5c:0e:90', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); $ports_id = $networkPort->add([ 'name' => 'eth1', @@ -2422,7 +2424,7 @@ public function testSwitchMacConnection3() 'itemtype' => $computer->getTypeName(1), 'mac' => 'bc:97:e1:5c:0e:91', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // add a virtual port (logical_number=0) with the same mac as eth0 $ports_id = $networkPort->add([ @@ -2433,7 +2435,7 @@ public function testSwitchMacConnection3() 'itemtype' => $computer->getTypeName(1), 'mac' => 'bc:97:e1:5c:0e:90', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -2443,16 +2445,16 @@ public function testSwitchMacConnection3() $inventory = new \Glpi\Inventory\Inventory($data); $CFG_GLPI["is_contact_autoupdate"] = 1; //reset to default - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); // Make sure there are no hubs - $this->integer(countElementsInTable($unmanaged->getTable()))->isIdenticalTo(0); + $this->assertSame(0, countElementsInTable($unmanaged->getTable())); // Verify that eth0 is the only port connected - $this->integer(countElementsInTable($networkPort_NetworkPort->getTable()))->isIdenticalTo(1); - $this->boolean($networkPort->getFromDBByCrit(['name' => 'eth0'])); - $this->boolean($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id']))->isTrue(); + $this->assertSame(1, countElementsInTable($networkPort_NetworkPort->getTable())); + $this->assertTrue($networkPort->getFromDBByCrit(['name' => 'eth0'])); + $this->assertTrue($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id'])); } public function testSwitchMacConnection4() @@ -2520,7 +2522,7 @@ public function testSwitchMacConnection4() $computer = getItemByTypeName('Computer', '_test_pc01'); $computers_id = $computer->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); // Add some ports $ports_id = $networkPort->add([ @@ -2531,7 +2533,7 @@ public function testSwitchMacConnection4() 'itemtype' => $computer->getTypeName(1), 'mac' => 'bc:97:e1:5c:0e:90', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); $ports_id = $networkPort->add([ 'name' => 'eth1', @@ -2541,7 +2543,7 @@ public function testSwitchMacConnection4() 'itemtype' => $computer->getTypeName(1), 'mac' => 'bc:97:e1:5c:0e:91', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // add a virtual port (logical_number=0) with the same mac as eth0 $ports_id = $networkPort->add([ @@ -2552,7 +2554,7 @@ public function testSwitchMacConnection4() 'itemtype' => $computer->getTypeName(1), 'mac' => 'bc:97:e1:5c:0e:90', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // add another virtual port $ports_id = $networkPort->add([ @@ -2563,7 +2565,7 @@ public function testSwitchMacConnection4() 'itemtype' => $computer->getTypeName(1), 'mac' => 'fe:54:00:dd:1d:4f', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // add another virtual port $ports_id = $networkPort->add([ @@ -2574,7 +2576,7 @@ public function testSwitchMacConnection4() 'itemtype' => $computer->getTypeName(1), 'mac' => 'fe:54:00:c0:97:8a', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // add another virtual port $ports_id = $networkPort->add([ @@ -2585,7 +2587,7 @@ public function testSwitchMacConnection4() 'itemtype' => $computer->getTypeName(1), 'mac' => 'fe:54:00:ff:04:b5', ]); - $this->integer($ports_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ports_id); // Import the switch into GLPI $converter = new \Glpi\Inventory\Converter(); @@ -2595,49 +2597,20 @@ public function testSwitchMacConnection4() $inventory = new \Glpi\Inventory\Inventory($data); $CFG_GLPI["is_contact_autoupdate"] = 1; //reset to default - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); // Make sure there are no hubs - $this->integer(countElementsInTable($unmanaged->getTable()))->isIdenticalTo(0); + $this->assertSame(0, countElementsInTable($unmanaged->getTable())); // Verify that eth0 is the only port connected - $this->integer(countElementsInTable($networkPort_NetworkPort->getTable()))->isIdenticalTo(1); - $this->boolean($networkPort->getFromDBByCrit(['name' => 'eth0'])); - $this->boolean($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id']))->isTrue(); + $this->assertSame(1, countElementsInTable($networkPort_NetworkPort->getTable())); + $this->assertTrue($networkPort->getFromDBByCrit(['name' => 'eth0'])); + $this->assertTrue($networkPort_NetworkPort->getFromDBForNetworkPort($networkPort->fields['id'])); } - public function testPrepareConnectionsProvider() + public static function prepareConnectionsProvider() { - $networkEquipment = new \NetworkEquipment(); - $networkPort = new \NetworkPort(); - - $networkEquipments_id = $networkEquipment->add([ - 'entities_id' => 0, - 'name' => 'sw001', - ]); - $this->integer($networkEquipments_id)->isGreaterThan(0); - - $mngtports_id = $networkPort->add([ - 'items_id' => $networkEquipments_id, - 'itemtype' => 'NetworkEquipment', - 'instantiation_type' => 'NetworkPortAggregate', - 'name' => 'management', - 'mac' => '2c:fa:a2:d1:b2:28', - ]); - $this->integer($mngtports_id)->isGreaterThan(0); - - $ports_id = $networkPort->add([ - 'name' => 'port47', - 'logical_number' => '1047', - 'instantiation_type' => 'NetworkPortEthernet', - 'items_id' => $networkEquipments_id, - 'itemtype' => 'NetworkEquipment', - 'ifdescr' => '47', - 'mac' => '2c:fa:a2:d1:b2:99', - ]); - $this->integer($ports_id)->isGreaterThan(0); - return [ ['json_source' => '{ @@ -2702,10 +2675,39 @@ public function testPrepareConnectionsProvider() } /** - * @dataProvider testPrepareConnectionsProvider + * @dataProvider prepareConnectionsProvider */ public function testPrepareConnections($json_source) { + $networkEquipment = new \NetworkEquipment(); + $networkPort = new \NetworkPort(); + + $networkEquipments_id = $networkEquipment->add([ + 'entities_id' => 0, + 'name' => 'sw001', + ]); + $this->assertGreaterThan(0, $networkEquipments_id); + + $mngtports_id = $networkPort->add([ + 'items_id' => $networkEquipments_id, + 'itemtype' => 'NetworkEquipment', + 'instantiation_type' => 'NetworkPortAggregate', + 'name' => 'management', + 'mac' => '2c:fa:a2:d1:b2:28', + ]); + $this->assertGreaterThan(0, $mngtports_id); + + $ports_id = $networkPort->add([ + 'name' => 'port47', + 'logical_number' => '1047', + 'instantiation_type' => 'NetworkPortEthernet', + 'items_id' => $networkEquipments_id, + 'itemtype' => 'NetworkEquipment', + 'ifdescr' => '47', + 'mac' => '2c:fa:a2:d1:b2:99', + ]); + $this->assertGreaterThan(0, $ports_id); + $json = json_decode($json_source); $networkEquipment = getItemByTypeName('NetworkEquipment', '_test_networkequipment_1'); @@ -2713,14 +2715,14 @@ public function testPrepareConnections($json_source) $asset = new \Glpi\Inventory\Asset\NetworkPort($networkEquipment, (array)$json->content->network_ports); $result = $asset->prepare(); - $this->array($result)->hasSize(1); + $this->assertCount(1, $result); $connections = $asset->getPart('connections'); - $this->array($connections)->hasSize(1); + $this->assertCount(1, $connections); $networkPort = current(current($connections)); - $this->boolean(property_exists($networkPort, 'logical_number'))->isTrue(); - $this->integer($networkPort->logical_number)->isEqualTo(1047); + $this->assertTrue(property_exists($networkPort, 'logical_number')); + $this->assertSame(1047, $networkPort->logical_number); } public function testUnmanagedNotDuplicatedAtEachInventoryWithLogicalNumber() @@ -2785,16 +2787,16 @@ public function testUnmanagedNotDuplicatedAtEachInventoryWithLogicalNumber() $inventory = $this->doInventory($xml_source, true); $network_device_id = $inventory->getItem()->fields['id']; - $this->integer($network_device_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $network_device_id); $unmanaged = new \Unmanaged(); - $this->boolean($unmanaged->getFromDBByCrit(['name' => 'SW_BATA-RdJ-vdi-1']))->isTrue(); + $this->assertTrue($unmanaged->getFromDBByCrit(['name' => 'SW_BATA-RdJ-vdi-1'])); //redo inventory and check if we still have a single Unmanaged $inventory = $this->doInventory($xml_source, true); $unmanaged = new \Unmanaged(); - $this->boolean($unmanaged->getFromDBByCrit(['name' => 'SW_BATA-RdJ-vdi-1']))->isTrue(); + $this->assertTrue($unmanaged->getFromDBByCrit(['name' => 'SW_BATA-RdJ-vdi-1'])); } @@ -2863,16 +2865,16 @@ public function testUnmanagedNotDuplicatedAtEachInventoryWithIfDescr() $inventory = $this->doInventory($xml_source, true); $network_device_id = $inventory->getItem()->fields['id']; - $this->integer($network_device_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $network_device_id); $unmanaged = new \Unmanaged(); - $this->boolean($unmanaged->getFromDBByCrit(['name' => 'FR-LUC-GCL-WAP-INTRA-239']))->isTrue(); + $this->assertTrue($unmanaged->getFromDBByCrit(['name' => 'FR-LUC-GCL-WAP-INTRA-239'])); //redo inventory and check if we still have a single Unmanaged $inventory = $this->doInventory($xml_source, true); $unmanaged = new \Unmanaged(); - $this->boolean($unmanaged->getFromDBByCrit(['name' => 'FR-LUC-GCL-WAP-INTRA-239']))->isTrue(); + $this->assertTrue($unmanaged->getFromDBByCrit(['name' => 'FR-LUC-GCL-WAP-INTRA-239'])); } @@ -2909,12 +2911,12 @@ public function testAssetTag() $inventory = $this->doInventory($xml_source, true); $network_device_id = $inventory->getItem()->fields['id']; - $this->integer($network_device_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $network_device_id); $networkEquipment = new \NetworkEquipment(); - $this->boolean($networkEquipment->getFromDB($network_device_id))->isTrue(); + $this->assertTrue($networkEquipment->getFromDB($network_device_id)); - $this->string($networkEquipment->fields['otherserial'])->isIdenticalTo('other_serial'); + $this->assertSame('other_serial', $networkEquipment->fields['otherserial']); } /** @@ -2936,8 +2938,8 @@ public function testStackedDellSwitchN3048P() var_dump($error); } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); $networkEquipment = new \NetworkEquipment(); $networkPort = new \NetworkPort(); @@ -2952,9 +2954,10 @@ public function testStackedDellSwitchN3048P() ]; foreach ($server_serial as $serial) { - $this->boolean( - $networkEquipment->getFromDBByCrit(['serial' => $serial]) - )->isTrue("Switch s/n $serial doesn't exist"); + $this->assertTrue( + $networkEquipment->getFromDBByCrit(['serial' => $serial]), + "Switch s/n $serial doesn't exist" + ); $found_np = $networkPort->find([ 'itemtype' => $networkEquipment->getType(), @@ -2962,7 +2965,7 @@ public function testStackedDellSwitchN3048P() ]); //53 because XML have 312 port with iftype 6 -> 52 port //and one management port, so 53 port per switch - $this->integer(count($found_np))->isIdenticalTo(53, 'Must have 53 ports'); + $this->assertCount(53, $found_np, 'Must have 53 ports'); } } @@ -3043,16 +3046,16 @@ public function testRuleMatchedLog() $inventory = $this->doInventory($xml_source, true); $network_device_id = $inventory->getItem()->fields['id']; - $this->integer($network_device_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $network_device_id); $networkEquipment = new \NetworkEquipment(); - $this->boolean($networkEquipment->getFromDB($network_device_id))->isTrue(); + $this->assertTrue($networkEquipment->getFromDB($network_device_id)); - $this->string($networkEquipment->fields['serial'])->isIdenticalTo('DFGKJ6545684SDF'); + $this->assertSame('DFGKJ6545684SDF', $networkEquipment->fields['serial']); $unmanaged = new \Unmanaged(); $found_unmanaged = $unmanaged->find(); - $this->integer(count($found_unmanaged))->isIdenticalTo(1); + $this->assertCount(1, $found_unmanaged); $rulematchedLog = new \RuleMatchedLog(); $found_rulematchedLog = $rulematchedLog->find( @@ -3061,7 +3064,7 @@ public function testRuleMatchedLog() 'items_id' => current($found_unmanaged)['id'], ] ); - $this->integer(count($found_rulematchedLog))->isIdenticalTo(1); + $this->assertCount(1, $found_rulematchedLog); //redo inventory $inventory = $this->doInventory($xml_source, true); @@ -3069,7 +3072,7 @@ public function testRuleMatchedLog() $unmanaged = new \Unmanaged(); $found_unmanaged = $unmanaged->find(); //get only one RuleMatchedLog - $this->integer(count($found_unmanaged))->isIdenticalTo(1); + $this->assertCount(1, $found_unmanaged); $rulematchedLog = new \RuleMatchedLog(); $found_rulematchedLog = $rulematchedLog->find( @@ -3079,7 +3082,7 @@ public function testRuleMatchedLog() ] ); //get two RuleMatchedLog - $this->integer(count($found_rulematchedLog))->isIdenticalTo(2); + $this->assertCount(2, $found_rulematchedLog); } /** @@ -3101,8 +3104,8 @@ public function testStackedCiscoSwitchC9300() var_dump($error); } } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isIdenticalTo([]); + $this->assertFalse($inventory->inError()); + $this->assertSame([], $inventory->getErrors()); $networkEquipment = new \NetworkEquipment(); $networkPort = new \NetworkPort(); @@ -3113,15 +3116,16 @@ public function testStackedCiscoSwitchC9300() ]; foreach ($server_serial as $serial => $nb_port) { - $this->boolean( - $networkEquipment->getFromDBByCrit(['serial' => $serial]) - )->isTrue("Switch s/n $serial doesn't exist"); + $this->assertTrue( + $networkEquipment->getFromDBByCrit(['serial' => $serial]), + "Switch s/n $serial doesn't exist" + ); $found_np = $networkPort->find([ 'itemtype' => $networkEquipment->getType(), 'items_id' => $networkEquipment->getID(), ]); - $this->integer(count($found_np))->isIdenticalTo($nb_port, 'Must have ' . $nb_port . ' ports'); + $this->assertCount($nb_port, $found_np, 'Must have ' . $nb_port . ' ports'); } } } diff --git a/tests/functional/Glpi/Inventory/Assets/NetworkPort.php b/phpunit/functional/Glpi/Inventory/Assets/NetworkPort.php similarity index 88% rename from tests/functional/Glpi/Inventory/Assets/NetworkPort.php rename to phpunit/functional/Glpi/Inventory/Assets/NetworkPort.php index 8764e82b16d..275d55a3f59 100644 --- a/tests/functional/Glpi/Inventory/Assets/NetworkPort.php +++ b/phpunit/functional/Glpi/Inventory/Assets/NetworkPort.php @@ -44,7 +44,7 @@ class NetworkPort extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -336,12 +336,13 @@ public function testPrepare($xml, $ports, $connections, $vlans, $aggregates) $neteq = getItemByTypeName('NetworkEquipment', 'My network equipment'); if ($neteq === false) { $neteq = new \NetworkEquipment(); - $this->integer( + $this->assertGreaterThan( + 0, $neteq->add([ 'name' => 'My network equipment', 'entities_id' => 0 ]) - )->isGreaterThan(0); + ); } $asset = new \Glpi\Inventory\Asset\NetworkPort($neteq, $json->content->network_ports); @@ -349,11 +350,11 @@ public function testPrepare($xml, $ports, $connections, $vlans, $aggregates) $results = $asset->prepare(); foreach ($results as $key => $result) { - $this->object($result)->isEqualTo(json_decode($ports[$key]), json_encode($result)); + $this->assertEquals(json_decode($ports[$key]), $result); } - $this->array($asset->getPart('connections'))->isEqualTo((array)json_decode($connections), json_encode($asset->getPart('connections'))); - $this->array($asset->getPart('vlans'))->isEqualTo((array)json_decode($vlans), json_encode($asset->getPart('vlans'))); - $this->array($asset->getPart('aggregates'))->isEqualTo(json_decode($aggregates, true), json_encode($asset->getPart('aggregates'))); + $this->assertEquals((array)json_decode($connections), $asset->getPart('connections')); + $this->assertEquals((array)json_decode($vlans), $asset->getPart('vlans')); + $this->assertEquals(json_decode($aggregates, true), $asset->getPart('aggregates')); } public function testNetworkPortMetrics() @@ -454,15 +455,15 @@ public function testNetworkPortMetrics() //check networkequipement $networkquipement_id = $inventory->getItem()->fields['id']; - $this->integer($networkquipement_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkquipement_id); //get networkport - $this->boolean($networkport->getFromDbByCrit(['itemtype' => 'NetworkEquipment', 'items_id' => $networkquipement_id, 'instantiation_type' => 'NetworkPortEthernet'])) - ->isTrue(); + $this->assertTrue( + $networkport->getFromDbByCrit(['itemtype' => 'NetworkEquipment', 'items_id' => $networkquipement_id, 'instantiation_type' => 'NetworkPortEthernet']) + ); //get networkport metric - $this->boolean($networkmetric->getFromDbByCrit(['networkports_id' => $networkport->fields['id']])) - ->isTrue(); + $this->assertTrue($networkmetric->getFromDbByCrit(['networkports_id' => $networkport->fields['id']])); $db_input = $networkmetric->fields; unset($db_input['date_creation']); @@ -477,12 +478,12 @@ public function testNetworkPortMetrics() "ifouterrors" => $ifouterrors, "networkports_id" => $networkport->fields['id'], ]; - $this->array($db_input)->isIdenticalTo($expected_input); + $this->assertSame($expected_input, $db_input); //no lock $lockedfield = new \Lockedfield(); - $this->boolean($lockedfield->isHandled($networkport))->isTrue(); - $this->array($lockedfield->getLockedValues($networkport->getType(), $networkport->fields['id']))->isEmpty(); + $this->assertTrue($lockedfield->isHandled($networkport)); + $this->assertEmpty($lockedfield->getLockedValues($networkport->getType(), $networkport->fields['id'])); //change 'date' to yesterday to get new metric after reimport (2nd step) $currentDate = new DateTime(date('Y-m-d')); @@ -490,8 +491,8 @@ public function testNetworkPortMetrics() $yesterday = $yesterdayTime->format('Y-m-d'); $networkmetric->fields['date'] = $yesterday; - $this->boolean($networkmetric->update($networkmetric->fields))->isTrue(); - $this->string($networkmetric->fields['date'])->isIdenticalTo($yesterday); + $this->assertTrue($networkmetric->update($networkmetric->fields)); + $this->assertSame($yesterday, $networkmetric->fields['date']); //Second step : import NetworkEquipement again but with new metrics //check metrics data for today @@ -515,12 +516,10 @@ public function testNetworkPortMetrics() //now we have two metrics, one for yesterday and one for today $metrics = $networkmetric->find(['networkports_id' => $networkport->fields['id']]); - $this->array($metrics) - ->hasSize(2); + $this->assertCount(2, $metrics); //get networkport metric for today - $this->boolean($networkmetric->getFromDbByCrit(['networkports_id' => $networkport->fields['id'], "date" => date('Y-m-d')])) - ->isTrue(); + $this->assertTrue($networkmetric->getFromDbByCrit(['networkports_id' => $networkport->fields['id'], "date" => date('Y-m-d')])); $db_input = $networkmetric->fields; unset($db_input['date_creation']); @@ -536,12 +535,12 @@ public function testNetworkPortMetrics() "ifouterrors" => $ifouterrors, "networkports_id" => $networkport->fields['id'], ]; - $this->array($db_input)->isIdenticalTo($expected_input); + $this->assertSame($expected_input, $db_input); //no lock $lockedfield = new \Lockedfield(); - $this->boolean($lockedfield->isHandled($networkport))->isTrue(); - $this->array($lockedfield->getLockedValues($networkport->getType(), $networkport->fields['id']))->isEmpty(); + $this->assertTrue($lockedfield->isHandled($networkport)); + $this->assertEmpty($lockedfield->getLockedValues($networkport->getType(), $networkport->fields['id'])); //Third step : import NetworkEquipement again but with new metrics //check that the previous data are updated @@ -564,15 +563,12 @@ public function testNetworkPortMetrics() //networkequipement inventory $inventory = $this->doInventory($xml_source, true); - //we still have two metrics, but today metrics are updated $metrics = $networkmetric->find(['networkports_id' => $networkport->fields['id']]); - $this->array($metrics) - ->hasSize(2); + $this->assertCount(2, $metrics); //get networkport metric for today - $this->boolean($networkmetric->getFromDbByCrit(['networkports_id' => $networkport->fields['id'], "date" => date('Y-m-d')])) - ->isTrue(); + $this->assertTrue($networkmetric->getFromDbByCrit(['networkports_id' => $networkport->fields['id'], "date" => date('Y-m-d')])); $db_input = $networkmetric->fields; unset($db_input['date_creation']); @@ -588,12 +584,12 @@ public function testNetworkPortMetrics() "ifouterrors" => $ifouterrors, "networkports_id" => $networkport->fields['id'], ]; - $this->array($db_input)->isIdenticalTo($expected_input); + $this->assertSame($expected_input, $db_input); //no lock $lockedfield = new \Lockedfield(); - $this->boolean($lockedfield->isHandled($networkport))->isTrue(); - $this->array($lockedfield->getLockedValues($networkport->getType(), $networkport->fields['id']))->isEmpty(); + $this->assertTrue($lockedfield->isHandled($networkport)); + $this->assertEmpty($lockedfield->getLockedValues($networkport->getType(), $networkport->fields['id'])); } public function testVlanChange() @@ -657,24 +653,25 @@ public function testVlanChange() //check networkequipement $networkquipement_id = $inventory->getItem()->fields['id']; - $this->integer($networkquipement_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkquipement_id); //get networkport - $this->boolean($networkport->getFromDbByCrit(['itemtype' => 'NetworkEquipment', 'items_id' => $networkquipement_id, 'instantiation_type' => 'NetworkPortEthernet'])) - ->isTrue(); + $this->assertTrue( + $networkport->getFromDbByCrit(['itemtype' => 'NetworkEquipment', 'items_id' => $networkquipement_id, 'instantiation_type' => 'NetworkPortEthernet']) + ); $networkports_id = $networkport->fields['id']; //get vlans - $this->boolean( + $this->assertTrue( $networkport_vlan->getFromDBByCrit(['networkports_id' => $networkports_id]) - )->isTrue(); + ); - $this->boolean( + $this->assertTrue( $vlan->getFromDB($networkport_vlan->fields['vlans_id']) - )->isTrue(); + ); $vlans_id = $vlan->fields['id']; - $this->string($vlan->fields['name'])->isIdenticalTo($vlanname); + $this->assertSame($vlanname, $vlan->fields['name']); //Second step : import NetworkEquipement again but with new vlan $oldname = $vlanname; @@ -684,23 +681,24 @@ public function testVlanChange() //networkequipement inventory $inventory = $this->doInventory($xml_source, true); - $this->integer($networkquipement_id)->isIdenticalTo($inventory->getItem()->fields['id']); + $this->assertSame($inventory->getItem()->fields['id'], $networkquipement_id); //get networkport - $this->boolean($networkport->getFromDbByCrit(['itemtype' => 'NetworkEquipment', 'items_id' => $networkquipement_id, 'instantiation_type' => 'NetworkPortEthernet'])) - ->isTrue(); - $this->integer($networkports_id)->isIdenticalTo($networkport->fields['id']); + $this->assertTrue( + $networkport->getFromDbByCrit(['itemtype' => 'NetworkEquipment', 'items_id' => $networkquipement_id, 'instantiation_type' => 'NetworkPortEthernet']) + ); + $this->assertSame($networkport->fields['id'], $networkports_id); - $this->boolean( + $this->assertTrue( $networkport_vlan->getFromDBByCrit(['networkports_id' => $networkports_id]) - )->isTrue(); - $this->integer($vlans_id)->isNotIdenticalTo($networkport_vlan->fields['vlans_id']); + ); + $this->assertNotEquals($networkport_vlan->fields['networkports_id'], $vlans_id); - $this->boolean( + $this->assertTrue( $vlan->getFromDB($networkport_vlan->fields['vlans_id']) - )->isTrue(); + ); - $this->string($vlan->fields['name'])->isIdenticalTo($vlanname); + $this->assertSame($vlanname, $vlan->fields['name']); } public function testIfaliasUpdate() @@ -764,14 +762,15 @@ public function testIfaliasUpdate() //check networkequipement $networkquipement_id = $inventory->getItem()->fields['id']; - $this->integer($networkquipement_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkquipement_id); //get networkport - $this->boolean($networkport->getFromDbByCrit(['itemtype' => 'NetworkEquipment', 'items_id' => $networkquipement_id, 'instantiation_type' => 'NetworkPortEthernet'])) - ->isTrue(); + $this->assertTrue( + $networkport->getFromDbByCrit(['itemtype' => 'NetworkEquipment', 'items_id' => $networkquipement_id, 'instantiation_type' => 'NetworkPortEthernet']) + ); //check alias - $this->string($networkport->fields['ifalias'])->isEqualTo('ACCESS vs HAV-S1700'); + $this->assertSame('ACCESS vs HAV-S1700', $networkport->fields['ifalias']); $xml_source = " @@ -829,14 +828,15 @@ public function testIfaliasUpdate() //check networkequipement $networkquipement_id = $inventory->getItem()->fields['id']; - $this->integer($networkquipement_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkquipement_id); //get networkport - $this->boolean($networkport->getFromDbByCrit(['itemtype' => 'NetworkEquipment', 'items_id' => $networkquipement_id, 'instantiation_type' => 'NetworkPortEthernet'])) - ->isTrue(); + $this->assertTrue( + $networkport->getFromDbByCrit(['itemtype' => 'NetworkEquipment', 'items_id' => $networkquipement_id, 'instantiation_type' => 'NetworkPortEthernet']) + ); //check alias - $this->string($networkport->fields['ifalias'])->isEqualTo('another alias'); + $this->assertSame('another alias', $networkport->fields['ifalias']); } public function testNetworkEquipmentInstanciationType() @@ -906,19 +906,19 @@ public function testNetworkEquipmentInstanciationType() //check networkequipement $networkquipement_id = $inventory->getItem()->fields['id']; - $this->integer($networkquipement_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $networkquipement_id); //get networkport - $this->boolean( + $this->assertTrue( $networkport->getFromDbByCrit([ 'itemtype' => 'NetworkEquipment', 'items_id' => $networkquipement_id, 'name' => 'radio0_ssid_id0' ]) - )->isTrue(); + ); //check type is correct - $this->string($networkport->fields['instantiation_type'])->isIdenticalTo('NetworkPortWifi'); + $this->assertSame('NetworkPortWifi', $networkport->fields['instantiation_type']); } public function testInstantiationType() @@ -1087,123 +1087,123 @@ public function testInstantiationType() //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('teclib-asus-desktop-2022-09-20-16-43-09') - ->string['name']->isIdenticalTo('teclib-asus-desktop-2022-09-20-16-43-09') - ->string['itemtype']->isIdenticalTo('Computer') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']) - ->integer['items_id']->isGreaterThan(0); + $this->assertIsArray($agent); + $this->assertSame('teclib-asus-desktop-2022-09-20-16-43-09', $agent['deviceid']); + $this->assertSame('teclib-asus-desktop-2022-09-20-16-43-09', $agent['name']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); + $this->assertGreaterThan(0, $agent['items_id']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check created networkport $networkport = new \NetworkPort(); // lo -> ethernet -> NetworkPortEthernet - $this->boolean($networkport->getFromDbByCrit( + $this->assertTrue($networkport->getFromDbByCrit( [ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'name' => 'enp3s0', 'instantiation_type' => 'NetworkPortEthernet' ] - ))->isTrue(); + )); // lo -> loopback -> NetworkPortLocal - $this->boolean($networkport->getFromDbByCrit( + $this->assertTrue($networkport->getFromDbByCrit( [ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'name' => 'lo', 'instantiation_type' => 'NetworkPortLocal' ] - ))->isTrue(); + )); // br-8f1b5a0d178c -> bridge -> NetworkPortEthernet (no NetworkPortBridge so use default NetworkPortEthernet ) - $this->boolean($networkport->getFromDbByCrit( + $this->assertTrue($networkport->getFromDbByCrit( [ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'name' => 'br-8f1b5a0d178c', 'instantiation_type' => 'NetworkPortEthernet' ] - ))->isTrue(); + )); // Intel(R) WiFi Link 5100 AGN -> wifi -> NetworkPortWifi - $this->boolean($networkport->getFromDbByCrit( + $this->assertTrue($networkport->getFromDbByCrit( [ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'name' => 'Intel(R) WiFi Link 5100 AGN', 'instantiation_type' => 'NetworkPortWifi' ] - ))->isTrue(); + )); // fibrechannel A -> fibrechannel -> NetworkPortFiberChannel - $this->boolean($networkport->getFromDbByCrit( + $this->assertTrue($networkport->getFromDbByCrit( [ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'name' => 'fibrechannel A', 'instantiation_type' => 'NetworkPortFiberChannel' ] - ))->isTrue(); + )); // bond0 -> aggregate -> NetworkPortAggregate - $this->boolean($networkport->getFromDbByCrit( + $this->assertTrue($networkport->getFromDbByCrit( [ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'name' => 'bond0', 'instantiation_type' => 'NetworkPortAggregate' ] - ))->isTrue(); + )); // eth3 -> alias -> NetworkPortAlias - $this->boolean($networkport->getFromDbByCrit( + $this->assertTrue($networkport->getFromDbByCrit( [ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'name' => 'eth3', 'instantiation_type' => 'NetworkPortAlias' ] - ))->isTrue(); + )); //Bluetooth -> bluetooth -> NetworkPortEthernet (no NetworkPortBluetooth so use default NetworkPortEthernet ) - $this->boolean($networkport->getFromDbByCrit( + $this->assertTrue($networkport->getFromDbByCrit( [ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'name' => 'Bluetooth', 'instantiation_type' => 'NetworkPortEthernet' ] - ))->isTrue(); + )); //Infiniband -> infiniband -> NetworkPortEthernet (no NetworkPortInfiniband so use default NetworkPortEthernet ) - $this->boolean($networkport->getFromDbByCrit( + $this->assertTrue($networkport->getFromDbByCrit( [ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'name' => 'Infiniband', 'instantiation_type' => 'NetworkPortEthernet' ] - ))->isTrue(); + )); //Dialup -> dialup -> NetworkPortDialup - $this->boolean($networkport->getFromDbByCrit( + $this->assertTrue($networkport->getFromDbByCrit( [ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'name' => 'Dialup', 'instantiation_type' => 'NetworkPortDialup' ] - ))->isTrue(); + )); } public function testInstantiationTypeUpdate() @@ -1283,34 +1283,33 @@ public function testInstantiationTypeUpdate() //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('teclib-asus-desktop-2022-09-20-16-43-09') - ->string['name']->isIdenticalTo('teclib-asus-desktop-2022-09-20-16-43-09') - ->string['itemtype']->isIdenticalTo('Computer') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']) - ->integer['items_id']->isGreaterThan(0); + $this->assertIsArray($agent); + $this->assertSame('teclib-asus-desktop-2022-09-20-16-43-09', $agent['deviceid']); + $this->assertSame('teclib-asus-desktop-2022-09-20-16-43-09', $agent['name']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); + $this->assertGreaterThan(0, $agent['items_id']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check created networkport $networkport1 = new \NetworkPort(); - // lo -> ethernet -> NetworkPortEthernet - $this->boolean($networkport1->getFromDbByCrit( + $this->assertTrue($networkport1->getFromDbByCrit( [ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'name' => 'lo', 'instantiation_type' => 'NetworkPortEthernet' ] - ))->isTrue(); + )); global $DB; $json_str = ' @@ -1388,15 +1387,15 @@ public function testInstantiationTypeUpdate() $networkport2 = new \NetworkPort(); // lo -> eloopback -> NetworkPortLocal - $this->boolean($networkport2->getFromDbByCrit( + $this->assertTrue($networkport2->getFromDbByCrit( [ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'name' => 'lo', 'instantiation_type' => 'NetworkPortLocal' ] - ))->isTrue(); + )); - $this->integer($networkport1->fields['id'])->isIdenticalTo($networkport2->fields['id']); + $this->assertSame($networkport2->fields['id'], $networkport1->fields['id']); } } diff --git a/tests/functional/Glpi/Inventory/Assets/OperatingSystem.php b/phpunit/functional/Glpi/Inventory/Assets/OperatingSystem.php similarity index 82% rename from tests/functional/Glpi/Inventory/Assets/OperatingSystem.php rename to phpunit/functional/Glpi/Inventory/Assets/OperatingSystem.php index 86fa2ffb319..3794064778c 100644 --- a/tests/functional/Glpi/Inventory/Assets/OperatingSystem.php +++ b/phpunit/functional/Glpi/Inventory/Assets/OperatingSystem.php @@ -46,7 +46,7 @@ class OperatingSystem extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -81,7 +81,7 @@ protected function assetProvider(): array 'install_date' => '2022-01-01', ] ] - ] + $this->fusionProvider(); + ] + self::commonProvider(); } /** @@ -100,9 +100,9 @@ public function testPrepare($nodes, $expected) $asset = new \Glpi\Inventory\Asset\OperatingSystem($computer, (array)$json->content->operatingsystem); $asset->setExtraData((array)$json->content); $conf = new \Glpi\Inventory\Conf(); - $this->boolean( + $this->assertTrue( $asset->checkConf($conf) - )->isTrue(); + ); $result = $asset->prepare(); if (!is_array($expected)) { $object = json_decode($expected); @@ -117,10 +117,10 @@ public function testPrepare($nodes, $expected) $tz->offset = '+0200'; $object->timezone = $tz; } - $this->object($result[0])->isEqualTo($object); + $this->assertEquals($object, $result[0]); } - protected function assetCleanOsProvider(): array + public static function assetCleanOsProvider(): array { $os_input = [ "fedora_01" => [ @@ -362,7 +362,7 @@ protected function assetCleanOsProvider(): array }' ]; } - return $data + $this->fusionProvider(); + return $data + self::commonProvider(); } /** @@ -379,11 +379,11 @@ public function testPrepareWithCleanOS($nodes, $expected) ], [ "sub_type" => - [ - RuleDictionnaryOperatingSystem::class, - RuleDictionnaryOperatingSystemEdition::class, - RuleDictionnaryOperatingSystemVersion::class, - ] + [ + RuleDictionnaryOperatingSystem::class, + RuleDictionnaryOperatingSystemEdition::class, + RuleDictionnaryOperatingSystemVersion::class, + ] ] ); @@ -398,9 +398,9 @@ public function testPrepareWithCleanOS($nodes, $expected) $asset = new \Glpi\Inventory\Asset\OperatingSystem($computer, (array)$json->content->operatingsystem); $asset->setExtraData((array)$json->content); $conf = new \Glpi\Inventory\Conf(); - $this->boolean( + $this->assertTrue( $asset->checkConf($conf) - )->isTrue(); + ); $result = $asset->prepare(); if (!is_array($expected)) { $object = json_decode($expected); @@ -428,7 +428,7 @@ public function testPrepareWithCleanOS($nodes, $expected) $result[0]->operatingsystemeditions_id = ''; } - $this->object($result[0])->isEqualTo($object); + $this->assertEquals($object, $result[0]); } private function buildXml($nodes) @@ -455,37 +455,9 @@ private function buildXml($nodes) return $xml; } - protected function fusionProvider(): array + public static function commonProvider(): array { $data = [ - // array( - // array( - // 'ARCH' => '', - // 'FULL_NAME' => '', - // 'KERNEL_NAME' => '', - // 'KERNEL_VERSION' => '', - // 'NAME' => '', - // 'SERVICE_PACK' => '' - // ), - // array( - // 'arch' => '', - // 'kernname' => '', - // 'kernversion' => '', - // 'os' => '', - // 'osversion' => '', - // 'servicepack' => '', - // 'edition' => '' - // ), - // array( - // 'arch' => '', - // 'kernname' => '', - // 'kernversion' => '', - // 'os' => '', - // 'osversion' => '', - // 'servicepack' => '', - // 'edition' => '' - // ) - // ), [ [ 'ARCH' => '64-bit', @@ -594,88 +566,6 @@ protected function fusionProvider(): array 'edition' => '' ] ], - /*[ - [ - 'ARCH' => '32-bit', - 'FULL_NAME' => 'Microsoft Windows Embedded Standard', - 'KERNEL_NAME' => 'MSWin32', - 'KERNEL_VERSION' => '6.1.7601', - 'NAME' => 'Windows', - 'SERVICE_PACK' => 'Service Pack 1' - ], - [ - 'arch' => '32-bit', - 'kernname' => 'MSWin32', - 'kernversion' => '6.1.7601', - 'os' => 'Windows', - 'osversion' => '', - 'servicepack' => 'Service Pack 1', - 'edition' => 'Embedded Standard' - ], - [ - 'arch' => '32-bit', - 'kernname' => 'MSWin32', - 'kernversion' => '6.1.7601', - 'os' => 'Microsoft Windows Embedded Standard', - 'osversion' => '', - 'servicepack' => 'Service Pack 1', - 'edition' => '' - ] - ]/*, //5 - [ - [ - 'FULL_NAME' => 'Microsoft® Windows Server® 2008 Standard', - 'KERNEL_NAME' => 'MSWin32', - 'KERNEL_VERSION' => '6.0.6002', - 'NAME' => 'Windows', - 'SERVICE_PACK' => 'Service Pack 2' - ], - [ - 'arch' => '', - 'kernname' => 'MSWin32', - 'kernversion' => '6.0.6002', - 'os' => 'Windows', - 'osversion' => '2008', - 'servicepack' => 'Service Pack 2', - 'edition' => 'Server® Standard' - ], - [ - 'arch' => '', - 'kernname' => 'MSWin32', - 'kernversion' => '6.0.6002', - 'os' => 'Microsoft® Windows Server® 2008 Standard', - 'osversion' => '', - 'servicepack' => 'Service Pack 2', - 'edition' => '' - ] - ], - [ - [ - 'FULL_NAME' => 'Microsoft(R) Windows(R) Server 2003, Standard Edition', - 'KERNEL_NAME' => 'MSWin32', - 'KERNEL_VERSION' => '5.2.3790', - 'NAME' => 'Windows', - 'SERVICE_PACK' => 'Service Pack 2' - ], - [ - 'arch' => '', - 'kernname' => 'MSWin32', - 'kernversion' => '5.2.3790', - 'os' => 'Windows', - 'osversion' => '2003', - 'servicepack' => 'Service Pack 2', - 'edition' => 'Server Standard Edition' - ], - [ - 'arch' => '', - 'kernname' => 'MSWin32', - 'kernversion' => '5.2.3790', - 'os' => 'Microsoft(R) Windows(R) Server 2003, Standard Edition', - 'osversion' => '', - 'servicepack' => 'Service Pack 2', - 'edition' => '' - ] - ],*/ [ [ 'FULL_NAME' => 'Microsoft Windows Server 2012 R2 Datacenter', @@ -1060,13 +950,15 @@ public function testHandle() { $computer = getItemByTypeName('Computer', '_test_pc01'); - //first, check there are no controller linked to this computer + //first, check there are no controller linked to this computer $ios = new \Item_OperatingSystem(); - $this->boolean($ios->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('An operating system is already linked to computer!'); + $this->assertFalse( + $ios->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'An operating system is already linked to computer!' + ); - //convert data - $expected = $this->assetProvider()[0]; + //convert data + $expected = $this::assetProvider()[0]; $converter = new \Glpi\Inventory\Converter(); $data = $converter->convert($this->buildXml($expected['nodes'])); @@ -1076,13 +968,15 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\OperatingSystem($computer, (array)$json->content->operatingsystem); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); - //handle + //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($ios->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Operating system has not been linked to computer :('); + $this->assertTrue( + $ios->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Operating system has not been linked to computer :(' + ); } public function testInventoryUpdate() @@ -1130,35 +1024,35 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $os_id = $os->add([ 'name' => 'Fedora 28 (Workstation Edition)' ]); - $this->integer($os_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $os_id); $cos_id = $cos->add([ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'operatingsystems_id' => $os_id ]); - $this->integer($cos_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $cos_id); $this->doInventory($xml_source, true); $list = $os->find(); - $this->integer(count($list))->isIdenticalTo(1); + $this->assertCount(1, $list); //check that OS is linked to computer, and is now dynamic $list = $cos->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($list))->isIdenticalTo(1); + $this->assertCount(1, $list); $theos = current($list); - $this->integer($theos['operatingsystems_id'])->isIdenticalTo($os_id); - $this->integer($theos['is_dynamic'])->isIdenticalTo(1); - $this->string($theos['install_date'])->isIdenticalTo("2022-01-01"); - $this->string($theos['company'])->isIdenticalTo("Test Company"); - $this->string($theos['owner'])->isIdenticalTo("Test Owner"); - $this->string($theos['hostid'])->isIdenticalTo("a8c07701"); + $this->assertSame($os_id, $theos['operatingsystems_id']); + $this->assertSame(1, $theos['is_dynamic']); + $this->assertSame("2022-01-01", $theos['install_date']); + $this->assertSame("Test Company", $theos['company']); + $this->assertSame("Test Owner", $theos['owner']); + $this->assertSame("a8c07701", $theos['hostid']); //Redo inventory, but with updated operating system @@ -1200,18 +1094,18 @@ public function testInventoryUpdate() //We now have 2 operating systems $list = $os->find(); - $this->integer(count($list))->isIdenticalTo(2); + $this->assertCount(2, $list); //but still only one linked to computer $list = $cos->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($list))->isIdenticalTo(1); + $this->assertCount(1, $list); $theos = current($list); - $this->integer($theos['operatingsystems_id'])->isNotIdenticalTo($os_id, 'Operating system link has not been updated'); - $this->integer($theos['is_dynamic'])->isIdenticalTo(1); - $this->string($theos['install_date'])->isIdenticalTo("2022-10-14"); - $this->string($theos['company'])->isIdenticalTo("Test Company 2"); - $this->string($theos['owner'])->isIdenticalTo("Test Owner 2"); - $this->string($theos['hostid'])->isIdenticalTo("a8c06c01"); + $this->assertNotEquals($os_id, $theos['operatingsystems_id'], 'Operating system link has not been updated'); + $this->assertSame(1, $theos['is_dynamic']); + $this->assertSame("2022-10-14", $theos['install_date']); + $this->assertSame("Test Company 2", $theos['company']); + $this->assertSame("Test Owner 2", $theos['owner']); + $this->assertSame("a8c06c01", $theos['hostid']); } public function testReplayRuleOnOS() @@ -1255,38 +1149,37 @@ public function testReplayRuleOnOS() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('test-pc002') - ->string['itemtype']->isIdenticalTo('Computer'); - + $this->assertIsArray($agent); + $this->assertSame('test-pc002', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check found OS $list = $os->find(); - $this->integer(count($list))->isIdenticalTo(1); + $this->assertCount(1, $list); //check found item_OS $list = $cos->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($list))->isIdenticalTo(1); + $this->assertCount(1, $list); $theos1 = current($list); - $os->getFromDBByCrit([ 'name' => 'Fedora 28 (Workstation Edition)']); - $this->integer($os->fields['id'])->isGreaterThan(0); + $this->assertTrue($os->getFromDBByCrit([ 'name' => 'Fedora 28 (Workstation Edition)'])); + $this->assertGreaterThan(0, $os->fields['id']); //check item_OS data - $this->integer($theos1['operatingsystems_id'])->isIdenticalTo($os->fields['id']); - $this->integer($theos1['is_dynamic'])->isIdenticalTo(1); - $this->string($theos1['install_date'])->isIdenticalTo("2022-01-01"); + $this->assertSame($os->fields['id'], $theos1['operatingsystems_id']); + $this->assertSame(1, $theos1['is_dynamic']); + $this->assertSame("2022-01-01", $theos1['install_date']); //enable rule to clean OS - $this->boolean( + $this->assertTrue( $DB->update( Rule::getTable(), [ @@ -1299,37 +1192,33 @@ public function testReplayRuleOnOS() ] ] ) - )->isTrue(); + ); //replay rule $this->login('glpi', 'glpi'); $os_dictionnary = new \RuleDictionnaryOperatingSystemCollection(); - $this->output( - function () use ($os_dictionnary) { - $os_dictionnary->replayRulesOnExistingDB(0, 0, [], []); - } - )->contains("Replay rules on existing database started on"); - + $this->expectOutputRegex('/.*Replay rules on existing database started on.*/'); + $os_dictionnary->replayRulesOnExistingDB(0, 0, [], []); $list = $cos->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($list))->isIdenticalTo(1); + $this->assertCount(1, $list); $theos2 = current($list); //same Item_OperatingSystem before and after - $this->integer($theos2['id'])->isIdenticalTo($theos1['id']); + $this->assertSame($theos1['id'], $theos2['id']); //load new OS name cleaned by dictionnary $os->getFromDBByCrit([ 'name' => 'Fedora']); - $this->integer($os->fields['id'])->isGreaterThan(0); + $this->assertGreaterThan(0, $os->fields['id']); //check item_OS data - $this->integer($theos2['operatingsystems_id'])->isIdenticalTo($os->fields['id']); - $this->integer($theos2['is_dynamic'])->isIdenticalTo(1); - $this->string($theos2['install_date'])->isIdenticalTo("2022-01-01"); + $this->assertSame($os->fields['id'], $theos2['operatingsystems_id']); + $this->assertSame(1, $theos2['is_dynamic']); + $this->assertSame("2022-01-01", $theos2['install_date']); //no lock $lockedfield = new \Lockedfield(); - $this->boolean($lockedfield->isHandled($computer))->isTrue(); - $this->array($lockedfield->getLockedValues($computer->getType(), $computers_id))->isEmpty(); + $this->assertTrue($lockedfield->isHandled($computer)); + $this->assertEmpty($lockedfield->getLockedValues($computer->getType(), $computers_id)); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Peripheral.php b/phpunit/functional/Glpi/Inventory/Assets/PeripheralTest.php similarity index 81% rename from tests/functional/Glpi/Inventory/Assets/Peripheral.php rename to phpunit/functional/Glpi/Inventory/Assets/PeripheralTest.php index bbdf4d744e2..54921f3d035 100644 --- a/tests/functional/Glpi/Inventory/Assets/Peripheral.php +++ b/phpunit/functional/Glpi/Inventory/Assets/PeripheralTest.php @@ -39,9 +39,9 @@ /* Test for inc/inventory/asset/controller.class.php */ -class Peripheral extends AbstractInventoryAsset +class PeripheralTest extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -79,7 +79,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\Peripheral($computer, $json->content->usbdevices); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } @@ -89,8 +89,10 @@ public function testHandle() //first, check there are no peripheral linked to this computer $idp = new \Computer_Item(); - $this->boolean($idp->getFromDbByCrit(['computers_id' => $computer->fields['id'], 'itemtype' => 'Peripheral'])) - ->isFalse('A peripheral is already linked to computer!'); + $this->assertFalse( + $idp->getFromDbByCrit(['computers_id' => $computer->fields['id'], 'itemtype' => 'Peripheral']), + 'A peripheral is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -103,7 +105,7 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Peripheral($computer, $json->content->usbdevices); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); @@ -113,8 +115,10 @@ public function testHandle() $asset->setAgent($agent); $asset->handle(); - $this->boolean($idp->getFromDbByCrit(['computers_id' => $computer->fields['id'], 'itemtype' => 'Peripheral'])) - ->isTrue('Peripheral has not been linked to computer :('); + $this->assertTrue( + $idp->getFromDbByCrit(['computers_id' => $computer->fields['id'], 'itemtype' => 'Peripheral']), + 'Peripheral has not been linked to computer :(' + ); } public function testInventoryUpdate() @@ -164,13 +168,13 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $manufacturer = new \Manufacturer(); $manufacturers_id = $manufacturer->add([ 'name' => 'Validity Sensors, Inc.' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $periph_1_id = $periph->add([ 'name' => 'VFS451 Fingerprint Reader', @@ -178,19 +182,19 @@ public function testInventoryUpdate() 'serial' => '00B0FE47AC85', 'entities_id' => 0 ]); - $this->integer($periph_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $periph_1_id); $item_periph_1_id = $item_periph->add([ 'computers_id' => $computers_id, 'itemtype' => \Peripheral::class, 'items_id' => $periph_1_id ]); - $this->integer($item_periph_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_periph_1_id); $manufacturers_id = $manufacturer->add([ 'name' => 'O2 Micro, Inc.' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $periph_2_id = $periph->add([ 'name' => 'OZ776 CCID Smartcard Reader', @@ -198,14 +202,14 @@ public function testInventoryUpdate() 'serial' => 'ABCDEF', 'entities_id' => 0 ]); - $this->integer($periph_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $periph_2_id); $item_periph_2_id = $item_periph->add([ 'computers_id' => $computers_id, 'items_id' => $periph_2_id, 'itemtype' => \Peripheral::class ]); - $this->integer($item_periph_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_periph_2_id); $manufacturers_id = $manufacturer->add([ 'name' => 'Logitech, Inc.' @@ -217,19 +221,19 @@ public function testInventoryUpdate() 'serial' => 'a0b2c3d4e5', 'entities_id' => 0 ]); - $this->integer($periph_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $periph_3_id); $item_periph_3_id = $item_periph->add([ 'computers_id' => $computers_id, 'items_id' => $periph_3_id, 'itemtype' => \Peripheral::class ]); - $this->integer($item_periph_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_periph_3_id); $periphs = $item_periph->find(['itemtype' => \Peripheral::class, 'computers_id' => $computers_id]); - $this->integer(count($periphs))->isIdenticalTo(3); + $this->assertCount(3, $periphs); foreach ($periphs as $p) { - $this->variable($p['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $p['is_dynamic']); } $this->nblogs = countElementsInTable(\Log::getTable()); @@ -247,23 +251,23 @@ public function testInventoryUpdate() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //we still have 3 peripherals $periphs = $periph->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($periphs))->isIdenticalTo(3); + $this->assertCount(3, $periphs); //we still have 3 peripherals items linked to the computer $periphs = $item_periph->find(['itemtype' => \Peripheral::class, 'computers_id' => $computers_id]); - $this->integer(count($periphs))->isIdenticalTo(3); + $this->assertCount(3, $periphs); //peripherals present in the inventory source are now dynamic $periphs = $item_periph->find(['itemtype' => \Peripheral::class, 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($periphs))->isIdenticalTo(2); + $this->assertCount(2, $periphs); //peripheral not present in the inventory is still not dynamic $periphs = $item_periph->find(['itemtype' => \Peripheral::class, 'computers_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($periphs))->isIdenticalTo(1); + $this->assertCount(1, $periphs); //Redo inventory, but with removed "Smartcard reader" peripheral $xml_source = " @@ -303,24 +307,24 @@ public function testInventoryUpdate() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //we still have 3 peripherals $periphs = $periph->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($periphs))->isIdenticalTo(3); + $this->assertCount(3, $periphs); //we now have 2 peripherals linked to computer only $periphs = $item_periph->find(); $periphs = $item_periph->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id]); - $this->integer(count($periphs))->isIdenticalTo(2); + $this->assertCount(2, $periphs); //peripheral present in the inventory source is still dynamic $periphs = $item_periph->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($periphs))->isIdenticalTo(1); + $this->assertCount(1, $periphs); //peripheral not present in the inventory is still not dynamic $periphs = $item_periph->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($periphs))->isIdenticalTo(1); + $this->assertCount(1, $periphs); } public function testInventoryMove() @@ -366,27 +370,27 @@ public function testInventoryMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Validity Sensors, Inc.']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we have 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); - $this->integer(current($peripherals)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $peripherals); + $this->assertSame($manufacturers_id, current($peripherals)['manufacturers_id']); //we have 1 peripheral items linked to the computer $peripherals = $item_peripheral->find(['itemtype' => 'peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //peripheral present in the inventory source is dynamic $peripherals = $item_peripheral->find(['itemtype' => 'peripheral', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //same inventory again $inventory = $this->doInventory($xml_source, true); @@ -401,19 +405,19 @@ public function testInventoryMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we still have only 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); - $this->integer(current($peripherals)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $peripherals); + $this->assertSame($manufacturers_id, current($peripherals)['manufacturers_id']); //we still have only 1 peripheral items linked to the computer $peripherals = $item_peripheral->find(['itemtype' => 'peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //same peripheral, but on another computer $xml_source_2 = " @@ -452,27 +456,27 @@ public function testInventoryMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_2_id = $inventory->getItem()->fields['id']; - $this->integer($computers_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_2_id); //we still have only 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); - $this->integer(current($peripherals)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $peripherals); + $this->assertSame($manufacturers_id, current($peripherals)['manufacturers_id']); //no longer linked on first computer inventoried $peripherals = $item_peripheral->find(['itemtype' => 'peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(0); + $this->assertCount(0, $peripherals); //but now linked on last inventoried computer $peripherals = $item_peripheral->find(['itemtype' => 'peripheral', 'computers_id' => $computers_2_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //peripheral is still dynamic $peripherals = $item_peripheral->find(['itemtype' => 'peripheral', 'computers_id' => $computers_2_id, 'is_dynamic' => 1]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //replay first computer inventory, peripheral is back \o/ $inventory = $this->doInventory($xml_source, true); @@ -487,24 +491,24 @@ public function testInventoryMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //we still have only 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); - $this->integer(current($peripherals)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $peripherals); + $this->assertSame($manufacturers_id, current($peripherals)['manufacturers_id']); //linked again on first computer inventoried $peripherals = $item_peripheral->find(['itemtype' => 'peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //no longer linked on last inventoried computer $peripherals = $item_peripheral->find(['itemtype' => 'peripheral', 'computers_id' => $computers_2_id]); - $this->integer(count($peripherals))->isIdenticalTo(0); + $this->assertCount(0, $peripherals); //peripheral is still dynamic $peripherals = $item_peripheral->find(['itemtype' => 'peripheral', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); } public function testInventoryNoMove() @@ -550,27 +554,27 @@ public function testInventoryNoMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Validity Sensors, Inc.']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we have 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); - $this->integer(current($peripherals)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $peripherals); + $this->assertSame($manufacturers_id, current($peripherals)['manufacturers_id']); //we have 1 peripheral items linked to the computer $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //peripheral present in the inventory source is dynamic $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //same inventory again $inventory = $this->doInventory($xml_source, true); @@ -585,23 +589,23 @@ public function testInventoryNoMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we still have only 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); - $this->integer(current($peripherals)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $peripherals); + $this->assertSame($manufacturers_id, current($peripherals)['manufacturers_id']); //we still have only 1 peripheral items linked to the computer $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //set to global management - $this->boolean($peripheral->getFromDB(current($peripherals)['items_id'])); - $this->boolean($peripheral->update(['id' => $peripheral->fields['id'], 'is_global' => \Config::GLOBAL_MANAGEMENT])); + $this->assertTrue($peripheral->getFromDB(current($peripherals)['items_id'])); + $this->assertTrue($peripheral->update(['id' => $peripheral->fields['id'], 'is_global' => \Config::GLOBAL_MANAGEMENT])); //same peripheral, but on another computer $xml_source_2 = " @@ -640,29 +644,29 @@ public function testInventoryNoMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_2_id = $inventory->getItem()->fields['id']; - $this->integer($computers_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_2_id); //we still have only 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); - $this->integer(current($peripherals)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $peripherals); + $this->assertSame($manufacturers_id, current($peripherals)['manufacturers_id']); //still linked on first computer inventoried $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //also linked on last inventoried computer $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_2_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //peripheral is still dynamic $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_2_id, 'is_dynamic' => 1]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); } public function testInventoryGlobalManagement() @@ -718,27 +722,27 @@ public function testInventoryGlobalManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Validity Sensors, Inc.']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we have 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); - $this->integer(current($peripherals)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $peripherals); + $this->assertSame($manufacturers_id, current($peripherals)['manufacturers_id']); //we have 1 peripheral items linked to the computer $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //peripheral present in the inventory source is dynamic $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //same peripheral, but on another computer $xml_source_2 = " @@ -787,29 +791,29 @@ public function testInventoryGlobalManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_2_id = $inventory->getItem()->fields['id']; - $this->integer($computers_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_2_id); //we still have only 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); - $this->integer(current($peripherals)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $peripherals); + $this->assertSame($manufacturers_id, current($peripherals)['manufacturers_id']); //still linked on first computer inventoried $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //also linked on last inventoried computer $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_2_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //peripheral is still dynamic $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_2_id, 'is_dynamic' => 1]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); } public function testInventoryUnitManagement() @@ -865,26 +869,26 @@ public function testInventoryUnitManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Validity Sensors, Inc.']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we have 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //we have 1 peripheral items linked to the computer $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //peripheral present in the inventory source is dynamic $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //same inventory again $inventory = $this->doInventory($xml_source, true); @@ -899,23 +903,23 @@ public function testInventoryUnitManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we still have only 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); - $this->integer(current($peripherals)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $peripherals); + $this->assertSame($manufacturers_id, current($peripherals)['manufacturers_id']); //we still have only 1 peripheral items linked to the computer $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //set to global management - $this->boolean($peripheral->getFromDB(current($peripherals)['items_id'])); - $this->boolean($peripheral->update(['id' => $peripheral->fields['id'], 'is_global' => \Config::GLOBAL_MANAGEMENT])); + $this->assertTrue($peripheral->getFromDB(current($peripherals)['items_id'])); + $this->assertTrue($peripheral->update(['id' => $peripheral->fields['id'], 'is_global' => \Config::GLOBAL_MANAGEMENT])); //same peripheral, but on another computer $xml_source_2 = " @@ -964,27 +968,27 @@ public function testInventoryUnitManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_2_id = $inventory->getItem()->fields['id']; - $this->integer($computers_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_2_id); //we still have only 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); - $this->integer(current($peripherals)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $peripherals); + $this->assertSame($manufacturers_id, current($peripherals)['manufacturers_id']); //no longer linked on first computer inventoried $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(0); + $this->assertCount(0, $peripherals); //but now linked on last inventoried computer $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_2_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //peripheral is still dynamic $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_2_id, 'is_dynamic' => 1]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //change default configuration to unit management $this->login(); @@ -1009,24 +1013,24 @@ public function testInventoryUnitManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //we still have only 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); - $this->integer(current($peripherals)['manufacturers_id'])->isIdenticalTo($manufacturers_id); + $this->assertCount(1, $peripherals); + $this->assertSame($manufacturers_id, current($peripherals)['manufacturers_id']); //linked again on first computer inventoried $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //no longer linked on last inventoried computer $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_2_id]); - $this->integer(count($peripherals))->isIdenticalTo(0); + $this->assertCount(0, $peripherals); //peripheral is still dynamic $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); } public function testInventoryImportOrNot() @@ -1062,11 +1066,11 @@ public function testInventoryImportOrNot() //per default, configuration allows peripheral import. change that. $this->login(); $conf = new \Glpi\Inventory\Conf(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'import_peripheral' => 0 ]) - )->isTrue(); + ); $this->logout(); //computer inventory with one peripheral @@ -1074,11 +1078,11 @@ public function testInventoryImportOrNot() //restore default configuration $this->login(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'import_peripheral' => 1 ]) - )->isTrue(); + ); $this->logOut(); //check for expected logs @@ -1091,14 +1095,14 @@ public function testInventoryImportOrNot() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //no peripheral linked to the computer $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(0); + $this->assertCount(0, $peripherals); //inventory again $this->doInventory($xml_source, true); @@ -1113,18 +1117,18 @@ public function testInventoryImportOrNot() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //we now have 1 peripheral $peripherals = $peripheral->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //we have 1 peripheral items linked to the computer $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); //peripheral present in the inventory source is dynamic $peripherals = $item_peripheral->find(['itemtype' => 'Peripheral', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($peripherals))->isIdenticalTo(1); + $this->assertCount(1, $peripherals); } } diff --git a/tests/functional/Glpi/Inventory/Assets/PowerSupply.php b/phpunit/functional/Glpi/Inventory/Assets/PowerSupply.php similarity index 86% rename from tests/functional/Glpi/Inventory/Assets/PowerSupply.php rename to phpunit/functional/Glpi/Inventory/Assets/PowerSupply.php index 80aa28d43b2..4dff4054f49 100644 --- a/tests/functional/Glpi/Inventory/Assets/PowerSupply.php +++ b/phpunit/functional/Glpi/Inventory/Assets/PowerSupply.php @@ -41,7 +41,7 @@ class PowerSupply extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -77,7 +77,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\PowerSupply($computer, $json->content->powersupplies); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -86,8 +86,10 @@ public function testHandle() //first, check there are no power supply linked to this computer $idp = new \Item_DevicePowerSupply(); - $this->boolean($idp->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A power supply is already linked to computer!'); + $this->assertFalse( + $idp->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A power supply is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -100,13 +102,15 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\PowerSupply($computer, $json->content->powersupplies); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($idp->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Power supply has not been linked to computer :('); + $this->assertTrue( + $idp->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Power supply has not been linked to computer :(' + ); } public function testInventoryUpdate() @@ -144,14 +148,14 @@ public function testInventoryUpdate() //we have 1 power supply $pws = $device_ps->find(); - $this->integer(count($pws))->isIdenticalTo(1); + $this->assertCount(1, $pws); //we have 1 power supply items linked to the computer $pws = $item_ps->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($pws))->isIdenticalTo(1); + $this->assertCount(1, $pws); //power supply present in the inventory source is dynamic $pws = $item_ps->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($pws))->isIdenticalTo(1); + $this->assertCount(1, $pws); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Printer.php b/phpunit/functional/Glpi/Inventory/Assets/PrinterTest.php similarity index 75% rename from tests/functional/Glpi/Inventory/Assets/Printer.php rename to phpunit/functional/Glpi/Inventory/Assets/PrinterTest.php index 905a196bcaa..37a48748819 100644 --- a/tests/functional/Glpi/Inventory/Assets/Printer.php +++ b/phpunit/functional/Glpi/Inventory/Assets/PrinterTest.php @@ -39,11 +39,11 @@ /* Test for inc/inventory/asset/printer.class.php */ -class Printer extends AbstractInventoryAsset +class PrinterTest extends AbstractInventoryAsset { const INV_FIXTURES = GLPI_ROOT . '/vendor/glpi-project/inventory_format/examples/'; - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -88,7 +88,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\Printer($computer, $json->content->printers); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testSnmpPrinter() @@ -103,86 +103,92 @@ public function testSnmpPrinter() $data = (array)$json->content; $inventory = new \Glpi\Inventory\Inventory(); - $this->boolean($inventory->setData($json))->isTrue(); + $this->assertTrue($inventory->setData($json)); $agent = new \Agent(); - $this->integer($agent->handleAgent($inventory->extractMetadata()))->isIdenticalTo(0); + $this->assertSame(0, $agent->handleAgent($inventory->extractMetadata())); $main = new \Glpi\Inventory\Asset\Printer($printer, $json); $main->setAgent($agent)->setExtraData($data); $main->checkConf(new \Glpi\Inventory\Conf()); $result = $main->prepare(); - $this->array($result)->hasSize(1); - $this->array((array)$result[0])->isIdenticalTo([ - 'autoupdatesystems_id' => 'GLPI Native Inventory', - 'last_inventory_update' => $date_now, - "is_deleted" => 0, - 'firmware' => '2409048_052887', - 'ips' => ['10.59.29.175'], - 'mac' => '00:68:eb:f2:be:10', - 'manufacturer' => 'Hewlett-Packard', - 'model' => 'HP LaserJet M507', - 'name' => 'NPIF2BE10', - 'serial' => 'PHCVN191TG', - 'type' => 'Printer', - 'uptime' => '7 days, 01:26:41.98', - 'printermodels_id' => 'HP LaserJet M507', - 'printertypes_id' => 'Printer', - 'manufacturers_id' => 'Hewlett-Packard', - 'snmpcredentials_id' => 4, - 'have_usb' => 0, - 'have_ethernet' => 1, - 'memory_size' => 512, - 'last_pages_counter' => 1802, - ]); + $this->assertCount(1, $result); + $this->assertEquals( + [ + 'autoupdatesystems_id' => 'GLPI Native Inventory', + 'last_inventory_update' => $date_now, + "is_deleted" => 0, + 'firmware' => '2409048_052887', + 'ips' => ['10.59.29.175'], + 'mac' => '00:68:eb:f2:be:10', + 'manufacturer' => 'Hewlett-Packard', + 'model' => 'HP LaserJet M507', + 'name' => 'NPIF2BE10', + 'serial' => 'PHCVN191TG', + 'type' => 'Printer', + 'uptime' => '7 days, 01:26:41.98', + 'printermodels_id' => 'HP LaserJet M507', + 'printertypes_id' => 'Printer', + 'manufacturers_id' => 'Hewlett-Packard', + 'snmpcredentials_id' => 4, + 'have_usb' => 0, + 'have_ethernet' => 1, + 'memory_size' => 512, + 'last_pages_counter' => 1802, + ], + (array)$result[0] + ); //no management port (network_device->ips same as network_port->ips) - $this->array($main->getNetworkPorts())->isIdenticalTo([]); - $this->array($main->getManagementPorts())->hasSize(0); + $this->assertSame([], $main->getNetworkPorts()); + $this->assertCount(0, $main->getManagementPorts()); $pcounter = new \stdClass(); $pcounter->rectoverso = 831; $pcounter->rv_pages = 831; $pcounter->total = 1802; $pcounter->total_pages = 1802; - $this->object($main->getCounters())->isEqualTo($pcounter); + $this->assertEquals($pcounter, $main->getCounters()); $main->handle(); - $this->boolean($main->areLinksHandled())->isTrue(); + $this->assertTrue($main->areLinksHandled()); - $this->boolean($printer->getFromDB($printer->fields['id']))->isTrue(); - $this->integer($printer->fields['last_pages_counter'])->isIdenticalTo($pcounter->total); + $this->assertTrue($printer->getFromDB($printer->fields['id'])); + $this->assertSame($pcounter->total, $printer->fields['last_pages_counter']); global $DB; $iterator = $DB->request([ 'FROM' => \PrinterLog::getTable(), 'WHERE' => ['printers_id' => $printer->fields['id']] ]); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); $result = $iterator->current(); unset($result['id']); - $this->array($result)->isEqualTo([ - 'printers_id' => $printer->fields['id'], - 'total_pages' => 1802, - 'bw_pages' => 0, - 'color_pages' => 0, - 'rv_pages' => 831, - 'prints' => 0, - 'bw_prints' => 0, - 'color_prints' => 0, - 'copies' => 0, - 'bw_copies' => 0, - 'color_copies' => 0, - 'scanned' => 0, - 'faxed' => 0, - 'date' => date('Y-m-d', strtotime($_SESSION['glpi_currenttime'])), - 'date_creation' => $_SESSION['glpi_currenttime'], - 'date_mod' => $_SESSION['glpi_currenttime'], - ]); + $this->assertEquals( + [ + 'printers_id' => $printer->fields['id'], + 'total_pages' => 1802, + 'bw_pages' => 0, + 'color_pages' => 0, + 'rv_pages' => 831, + 'prints' => 0, + 'bw_prints' => 0, + 'color_prints' => 0, + 'copies' => 0, + 'bw_copies' => 0, + 'color_copies' => 0, + 'scanned' => 0, + 'faxed' => 0, + 'date' => date('Y-m-d', strtotime($_SESSION['glpi_currenttime'])), + 'date_creation' => $_SESSION['glpi_currenttime'], + 'date_mod' => $_SESSION['glpi_currenttime'], + ], + $result + ); } public function testSnmpPrinterManagementPortAdded() @@ -201,51 +207,59 @@ public function testSnmpPrinterManagementPortAdded() $data = (array)$json->content; $inventory = new \Glpi\Inventory\Inventory(); - $this->boolean($inventory->setData($json))->isTrue(); + $this->assertTrue($inventory->setData($json)); $agent = new \Agent(); - $this->integer($agent->handleAgent($inventory->extractMetadata()))->isIdenticalTo(0); + $this->assertSame(0, $agent->handleAgent($inventory->extractMetadata())); $main = new \Glpi\Inventory\Asset\Printer($printer, $json); $main->setAgent($agent)->setExtraData($data); $main->checkConf(new \Glpi\Inventory\Conf()); $result = $main->prepare(); - $this->array($result)->hasSize(1); - $this->array((array)$result[0])->isIdenticalTo([ - 'autoupdatesystems_id' => 'GLPI Native Inventory', - 'last_inventory_update' => $date_now, - "is_deleted" => 0, - 'firmware' => '8745213_951236', - 'ips' => ['10.59.29.176'], - 'mac' => '00:85:eb:f4:be:20', - 'manufacturer' => 'Canon', - 'model' => 'Canon MX 5970', - 'name' => 'MX5970', - 'serial' => 'SDFSDF9874', - 'type' => 'Printer', - 'uptime' => '8 days, 01:26:41.98', - 'printermodels_id' => 'Canon MX 5970', - 'printertypes_id' => 'Printer', - 'manufacturers_id' => 'Canon', - 'snmpcredentials_id' => 4, - 'have_usb' => 0, - 'have_ethernet' => 1, - 'memory_size' => 256, - 'last_pages_counter' => 800 - ]); + $this->assertCount(1, $result); + $this->assertEquals( + [ + 'autoupdatesystems_id' => 'GLPI Native Inventory', + 'last_inventory_update' => $date_now, + "is_deleted" => 0, + 'firmware' => '8745213_951236', + 'ips' => ['10.59.29.176'], + 'mac' => '00:85:eb:f4:be:20', + 'manufacturer' => 'Canon', + 'model' => 'Canon MX 5970', + 'name' => 'MX5970', + 'serial' => 'SDFSDF9874', + 'type' => 'Printer', + 'uptime' => '8 days, 01:26:41.98', + 'printermodels_id' => 'Canon MX 5970', + 'printertypes_id' => 'Printer', + 'manufacturers_id' => 'Canon', + 'snmpcredentials_id' => 4, + 'have_usb' => 0, + 'have_ethernet' => 1, + 'memory_size' => 256, + 'last_pages_counter' => 800 + ], + (array)$result[0] + ); //get one management port only - $this->array($mports = $main->getManagementPorts())->hasSize(1)->hasKey('management'); - $this->array((array)$mports['management'])->isIdenticalTo([ - 'mac' => '00:85:eb:f4:be:20', - 'name' => 'Management', - 'netname' => 'internal', - 'instantiation_type' => 'NetworkPortAggregate', - 'is_internal' => true, - 'ipaddress' => [ - '10.59.29.176' - ] - ]); + $mports = $main->getManagementPorts(); + $this->assertCount(1, $mports); + $this->assertArrayHasKey('management', $mports); + $this->assertSame( + [ + 'mac' => '00:85:eb:f4:be:20', + 'name' => 'Management', + 'netname' => 'internal', + 'instantiation_type' => 'NetworkPortAggregate', + 'is_internal' => true, + 'ipaddress' => [ + '10.59.29.176' + ] + ], + (array)$mports['management'] + ); //do real inventory to check dataDB $json_str = file_get_contents(self::INV_FIXTURES . 'printer_2.json'); @@ -253,11 +267,11 @@ public function testSnmpPrinterManagementPortAdded() $this->doInventory($json); $printer = new \Printer(); - $this->boolean($printer->getFromDbByCrit(['name' => 'MX5970', 'serial' => 'SDFSDF9874']))->isTrue(); + $this->assertTrue($printer->getFromDbByCrit(['name' => 'MX5970', 'serial' => 'SDFSDF9874'])); $np = new \NetworkPort(); - $this->boolean($np->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate']))->isTrue(); - $this->boolean($np->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortEthernet']))->isTrue(); + $this->assertTrue($np->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate'])); + $this->assertTrue($np->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortEthernet'])); //remove printer for other test $printer->delete($printer->fields); @@ -279,41 +293,44 @@ public function testSnmpPrinterManagementPortExcluded() $data = (array)$json->content; $inventory = new \Glpi\Inventory\Inventory(); - $this->boolean($inventory->setData($json))->isTrue(); + $this->assertTrue($inventory->setData($json)); $agent = new \Agent(); - $this->integer($agent->handleAgent($inventory->extractMetadata()))->isIdenticalTo(0); + $this->assertSame(0, $agent->handleAgent($inventory->extractMetadata())); $main = new \Glpi\Inventory\Asset\Printer($printer, $json); $main->setAgent($agent)->setExtraData($data); $main->checkConf(new \Glpi\Inventory\Conf()); $result = $main->prepare(); - $this->array($result)->hasSize(1); - $this->array((array)$result[0])->isIdenticalTo([ - 'autoupdatesystems_id' => 'GLPI Native Inventory', - 'last_inventory_update' => $date_now, - "is_deleted" => 0, - 'firmware' => '8745213_951236', - 'ips' => ['10.59.29.176'], - 'mac' => '00:85:eb:f4:be:20', - 'manufacturer' => 'Canon', - 'model' => 'Canon MX 5970', - 'name' => 'MX5970', - 'serial' => 'SDFSDF9874', - 'type' => 'Printer', - 'uptime' => '8 days, 01:26:41.98', - 'printermodels_id' => 'Canon MX 5970', - 'printertypes_id' => 'Printer', - 'manufacturers_id' => 'Canon', - 'snmpcredentials_id' => 4, - 'have_usb' => 0, - 'have_ethernet' => 1, - 'memory_size' => 256, - 'last_pages_counter' => 800 - ]); + $this->assertCount(1, $result); + $this->assertSame( + [ + 'autoupdatesystems_id' => 'GLPI Native Inventory', + 'last_inventory_update' => $date_now, + "is_deleted" => 0, + 'firmware' => '8745213_951236', + 'ips' => ['10.59.29.176'], + 'mac' => '00:85:eb:f4:be:20', + 'manufacturer' => 'Canon', + 'model' => 'Canon MX 5970', + 'name' => 'MX5970', + 'serial' => 'SDFSDF9874', + 'type' => 'Printer', + 'uptime' => '8 days, 01:26:41.98', + 'printermodels_id' => 'Canon MX 5970', + 'printertypes_id' => 'Printer', + 'manufacturers_id' => 'Canon', + 'snmpcredentials_id' => 4, + 'have_usb' => 0, + 'have_ethernet' => 1, + 'memory_size' => 256, + 'last_pages_counter' => 800 + ], + (array)$result[0] + ); //get no management port - $this->array($main->getManagementPorts())->hasSize(0); + $this->assertCount(0, $main->getManagementPorts()); //do real inventory to check dataDB $json_str = file_get_contents(self::INV_FIXTURES . 'printer_3.json'); @@ -321,19 +338,20 @@ public function testSnmpPrinterManagementPortExcluded() $this->doInventory($json); $printer = new \Printer(); - $this->boolean($printer->getFromDbByCrit(['name' => 'MX5970', 'serial' => 'SDFSDF9874']))->isTrue(); + $this->assertTrue($printer->getFromDbByCrit(['name' => 'MX5970', 'serial' => 'SDFSDF9874'])); //2 NetworkPort $np = new \NetworkPort(); - $this->integer( + $this->assertSame( + 2, countElementsInTable( $np::getTable(), [['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortEthernet']] ) - )->isIdenticalTo(2); + ); //0 NetworkPortAggregate - $this->boolean($np->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate']))->isFalse(); + $this->assertFalse($np->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate'])); //remove printer for other test $printer->delete($printer->fields); @@ -386,22 +404,22 @@ public function testInventoryMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we have 1 printer $printers = $printer->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //we have 1 printer items linked to the computer $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //printer present in the inventory source is dynamic $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //same inventory again $inventory = $this->doInventory($xml_source, true); @@ -416,18 +434,18 @@ public function testInventoryMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we still have only 1 printer $printers = $printer->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //we still have only 1 printer items linked to the computer $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //same printer, but on another computer $xml_source_2 = " @@ -470,26 +488,26 @@ public function testInventoryMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_2_id = $inventory->getItem()->fields['id']; - $this->integer($computers_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_2_id); //we still have only 1 printer $printers = $printer->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //no longer linked on first computer inventoried $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_id]); - $this->integer(count($printers))->isIdenticalTo(0); + $this->assertCount(0, $printers); //but now linked on last inventoried computer $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_2_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //printer is still dynamic $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_2_id, 'is_dynamic' => 1]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //replay first computer inventory, printer is back \o/ $inventory = $this->doInventory($xml_source, true); @@ -504,23 +522,23 @@ public function testInventoryMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //we still have only 1 printer $printers = $printer->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //linked again on first computer inventoried $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //no longer linked on last inventoried computer $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_2_id]); - $this->integer(count($printers))->isIdenticalTo(0); + $this->assertCount(0, $printers); //printer is still dynamic $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); } public function testInventoryNoMove() @@ -570,18 +588,18 @@ public function testInventoryNoMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we have 1 printer items linked to the computer $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //set to global management - $this->boolean($printer->getFromDB(current($printers)['items_id'])); - $this->boolean($printer->update(['id' => $printer->fields['id'], 'is_global' => \Config::GLOBAL_MANAGEMENT])); + $this->assertTrue($printer->getFromDB(current($printers)['items_id'])); + $this->assertTrue($printer->update(['id' => $printer->fields['id'], 'is_global' => \Config::GLOBAL_MANAGEMENT])); //same printer, but on another computer $xml_source_2 = " @@ -624,22 +642,22 @@ public function testInventoryNoMove() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_2_id = $inventory->getItem()->fields['id']; - $this->integer($computers_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_2_id); //we still have only 1 printer $printers = $printer->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //still linked on first computer inventoried $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //also linked on last inventoried computer $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_2_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); } public function testInventoryGlobalManagement() @@ -699,17 +717,17 @@ public function testInventoryGlobalManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we have 1 printer items linked to the computer $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); - $this->boolean($printer->getFromDB(current($printers)['items_id'])); - $this->boolean($printer->update(['id' => $printer->fields['id'], 'is_global' => 1])); + $this->assertTrue($printer->getFromDB(current($printers)['items_id'])); + $this->assertTrue($printer->update(['id' => $printer->fields['id'], 'is_global' => 1])); //same printer, but on another computer $xml_source_2 = " @@ -762,22 +780,22 @@ public function testInventoryGlobalManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_2_id = $inventory->getItem()->fields['id']; - $this->integer($computers_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_2_id); //we still have only 1 printer $printers = $printer->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //still linked on first computer inventoried $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //also linked on last inventoried computer $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_2_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); } public function testInventoryUnitManagement() @@ -837,22 +855,22 @@ public function testInventoryUnitManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we have 1 printer $printers = $printer->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //we have 1 printer items linked to the computer $printers = $item_printer->find(['itemtype' => 'Printer', 'computers_id' => $computers_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //printer present in the inventory source is dynamic $printers = $item_printer->find(['itemtype' => 'Printer', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //same inventory again $inventory = $this->doInventory($xml_source, true); @@ -867,22 +885,22 @@ public function testInventoryUnitManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //we still have only 1 printer $printers = $printer->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //we still have only 1 printer items linked to the computer $printers = $item_printer->find(['itemtype' => 'Printer', 'computers_id' => $computers_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //set to global management - $this->boolean($printer->getFromDB(current($printers)['items_id'])); - $this->boolean($printer->update(['id' => $printer->fields['id'], 'is_global' => \Config::GLOBAL_MANAGEMENT])); + $this->assertTrue($printer->getFromDB(current($printers)['items_id'])); + $this->assertTrue($printer->update(['id' => $printer->fields['id'], 'is_global' => \Config::GLOBAL_MANAGEMENT])); //same printer, but on another computer $xml_source_2 = " @@ -935,26 +953,26 @@ public function testInventoryUnitManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_2_id = $inventory->getItem()->fields['id']; - $this->integer($computers_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_2_id); //we still have only 1 printer $printers = $printer->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //no longer linked on first computer inventoried $printers = $item_printer->find(['itemtype' => 'Printer', 'computers_id' => $computers_id]); - $this->integer(count($printers))->isIdenticalTo(0); + $this->assertCount(0, $printers); //but now linked on last inventoried computer $printers = $item_printer->find(['itemtype' => 'Printer', 'computers_id' => $computers_2_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //printer is still dynamic $printers = $item_printer->find(['itemtype' => 'Printer', 'computers_id' => $computers_2_id, 'is_dynamic' => 1]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //change default configuration to unit management $this->login(); @@ -979,23 +997,23 @@ public function testInventoryUnitManagement() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //we still have only 1 printer $printers = $printer->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //linked again on first computer inventoried $printers = $item_printer->find(['itemtype' => 'Printer', 'computers_id' => $computers_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //no longer linked on last inventoried computer $printers = $item_printer->find(['itemtype' => 'Printer', 'computers_id' => $computers_2_id]); - $this->integer(count($printers))->isIdenticalTo(0); + $this->assertCount(0, $printers); //printer is still dynamic $printers = $item_printer->find(['itemtype' => 'Printer', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); } public function testPrinterIgnoreImport() @@ -1013,29 +1031,31 @@ public function testPrinterIgnoreImport() 'sub_type' => 'RuleDictionnaryPrinter', 'ranking' => 1 ]); - $this->integer($rule_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_id); // Add criteria $rulecriteria = new \RuleCriteria(get_class($rule)); - $this->integer( + $this->assertGreaterThan( + 0, $rulecriteria->add([ 'rules_id' => $rule_id, 'criteria' => "name", 'pattern' => 'HP Deskjet 2540', 'condition' => 0 ]) - )->isGreaterThan(0); + ); // Add action $ruleaction = new \RuleAction(get_class($rule)); - $this->integer( + $this->assertGreaterThan( + 0, $ruleaction->add([ 'rules_id' => $rule_id, 'action_type' => 'assign', 'field' => '_ignore_import', 'value' => '1' ]) - )->isGreaterThan(0); + ); $xml_source = " @@ -1082,14 +1102,14 @@ public function testPrinterIgnoreImport() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $item_printer = new \Computer_Item(); $printers = $item_printer->find(['computers_id' => $inventory->getItem()->fields['id'], 'itemtype' => 'Printer']); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); - $this->boolean($printer->getFromDB(current($printers)['items_id']))->isTrue(); - $this->string($printer->fields['name'])->isIdenticalTo('HP Color LaserJet Pro MFP M476 PCL 6'); + $this->assertTrue($printer->getFromDB(current($printers)['items_id'])); + $this->assertSame('HP Color LaserJet Pro MFP M476 PCL 6', $printer->fields['name']); } public function testPrinterRenamedImport() @@ -1100,7 +1120,7 @@ public function testPrinterRenamedImport() $printer = new \Printer(); $manufacturer = new \Manufacturer(); - $this->integer($manufacturer->add(['name' => 'HP inc.']))->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturer->add(['name' => 'HP inc.'])); $rulecollection = new \RuleDictionnaryPrinterCollection(); $rule = $rulecollection->getRuleClass(); @@ -1111,41 +1131,44 @@ public function testPrinterRenamedImport() 'sub_type' => 'RuleDictionnaryPrinter', 'ranking' => 2 ]); - $this->integer($rule_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_id); // Add criteria $rule = $rulecollection->getRuleClass(); $rulecriteria = new \RuleCriteria(get_class($rule)); - $this->integer( + $this->assertGreaterThan( + 0, $rulecriteria->add([ 'rules_id' => $rule_id, 'criteria' => "name", 'pattern' => 'HP Deskjet 2540', 'condition' => 0 ]) - )->isGreaterThan(0); + ); // Add action $ruleaction = new \RuleAction(get_class($rule)); - $this->integer( + $this->assertGreaterThan( + 0, $ruleaction->add([ 'rules_id' => $rule_id, 'action_type' => 'assign', 'field' => 'name', 'value' => 'HP Deskjet 2540 - renamed' ]) - )->isGreaterThan(0); + ); // Add action $ruleaction = new \RuleAction(get_class($rule)); - $this->integer( + $this->assertGreaterThan( + 0, $ruleaction->add([ 'rules_id' => $rule_id, 'action_type' => 'assign', 'field' => 'manufacturer', 'value' => $manufacturer->fields['id'] ]) - )->isGreaterThan(0); + ); // Add action $ruleaction = new \RuleAction(get_class($rule)); @@ -1207,23 +1230,23 @@ public function testPrinterRenamedImport() ] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computer->getFromDBByCrit(['serial' => 'ggheb7ne7']); $item_printer = new \Computer_Item(); $printers = $item_printer->find(['computers_id' => $inventory->getItem()->fields['id'], 'itemtype' => 'Printer']); - $this->integer(count($printers))->isIdenticalTo(2); + $this->assertCount(2, $printers); $printer1 = array_pop($printers); - $this->boolean($printer->getFromDB($printer1['items_id']))->isTrue(); - $this->string($printer->fields['name'])->isIdenticalTo('HP Deskjet 2540 - renamed'); - $this->integer($printer->fields['manufacturers_id'])->isIdenticalTo($manufacturer->fields['id']); - $this->integer($printer->fields['is_global'])->isIdenticalTo(0); + $this->assertTrue($printer->getFromDB($printer1['items_id'])); + $this->assertSame('HP Deskjet 2540 - renamed', $printer->fields['name']); + $this->assertSame($manufacturer->fields['id'], $printer->fields['manufacturers_id']); + $this->assertSame(0, $printer->fields['is_global']); $printer2 = array_pop($printers); - $this->boolean($printer->getFromDB($printer2['items_id']))->isTrue(); - $this->string($printer->fields['name'])->isIdenticalTo('HP Color LaserJet Pro MFP M476 PCL 6'); + $this->assertTrue($printer->getFromDB($printer2['items_id'])); + $this->assertSame('HP Color LaserJet Pro MFP M476 PCL 6', $printer->fields['name']); } public function testInventoryImportOrNot() @@ -1263,11 +1286,11 @@ public function testInventoryImportOrNot() //per default, configuration allows printer import. change that. $this->login(); $conf = new \Glpi\Inventory\Conf(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'import_printer' => 0 ]) - )->isTrue(); + ); $this->logout(); //computer inventory with one printer @@ -1275,11 +1298,11 @@ public function testInventoryImportOrNot() //restore default configuration $this->login(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'import_printer' => 1 ]) - )->isTrue(); + ); $this->logOut(); //check for expected logs @@ -1292,14 +1315,14 @@ public function testInventoryImportOrNot() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); $computers_id = $inventory->getItem()->fields['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //no printer linked to the computer $printers = $printer->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($printers))->isIdenticalTo(0); + $this->assertCount(0, $printers); //inventory again $this->doInventory($xml_source, true); @@ -1314,19 +1337,19 @@ public function testInventoryImportOrNot() 'NOT' => ['itemtype' => \Config::class] ] ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //we now have 1 printer $printers = $printer->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //we have 1 printer items linked to the computer $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_id]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); //printer present in the inventory source is dynamic $printers = $item_printer->find(['itemtype' => 'printer', 'computers_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($printers))->isIdenticalTo(1); + $this->assertCount(1, $printers); } public function testSnmpPrinterDiscoveryUpdateAllowed() @@ -1342,54 +1365,56 @@ public function testSnmpPrinterDiscoveryUpdateAllowed() $data = (array)$json->content; $inventory = new \Glpi\Inventory\Inventory(); - $this->boolean($inventory->setData($json))->isTrue(); + $this->assertTrue($inventory->setData($json)); $agent = new \Agent(); - $this->integer($agent->handleAgent($inventory->extractMetadata()))->isIdenticalTo(0); + $this->assertSame(0, $agent->handleAgent($inventory->extractMetadata())); $main = new \Glpi\Inventory\Asset\Printer($printer, $json); $main->setAgent($agent)->setExtraData($data); $main->checkConf(new \Glpi\Inventory\Conf()); $main->setDiscovery(true); $result = $main->prepare(); - $this->array($result)->hasSize(1); - $this->array((array)$result[0])->isIdenticalTo([ - 'autoupdatesystems_id' => 'GLPI Native Inventory', - 'last_inventory_update' => $date_now, - "is_deleted" => 0, - 'firmware' => '2409048_052887', - 'ips' => ['10.59.29.175'], - 'mac' => '00:68:eb:f2:be:10', - 'manufacturer' => 'Hewlett-Packard', - 'model' => 'HP LaserJet M507', - 'name' => 'NPIF2BE10', - 'serial' => 'PHCVN191TG', - 'type' => 'Printer', - 'uptime' => '7 days, 01:26:41.98', - 'printermodels_id' => 'HP LaserJet M507', - 'printertypes_id' => 'Printer', - 'manufacturers_id' => 'Hewlett-Packard', - 'snmpcredentials_id' => 4, - 'have_usb' => 0, - 'have_ethernet' => 1, - 'memory_size' => 512, - 'last_pages_counter' => 1802, - ]); - - - $this->array($main->getNetworkPorts())->isIdenticalTo([]); + $this->assertCount(1, $result); + $this->assertSame( + [ + 'autoupdatesystems_id' => 'GLPI Native Inventory', + 'last_inventory_update' => $date_now, + "is_deleted" => 0, + 'firmware' => '2409048_052887', + 'ips' => ['10.59.29.175'], + 'mac' => '00:68:eb:f2:be:10', + 'manufacturer' => 'Hewlett-Packard', + 'model' => 'HP LaserJet M507', + 'name' => 'NPIF2BE10', + 'serial' => 'PHCVN191TG', + 'type' => 'Printer', + 'uptime' => '7 days, 01:26:41.98', + 'printermodels_id' => 'HP LaserJet M507', + 'printertypes_id' => 'Printer', + 'manufacturers_id' => 'Hewlett-Packard', + 'snmpcredentials_id' => 4, + 'have_usb' => 0, + 'have_ethernet' => 1, + 'memory_size' => 512, + 'last_pages_counter' => 1802, + ], + (array)$result[0] + ); + + $this->assertSame([], $main->getNetworkPorts()); //Since this -> https://github.com/glpi-project/glpi/pull/12197 //management port is not created if is known from port list of printer. - $this->array($main->getManagementPorts())->hasSize(0); + $this->assertCount(0, $main->getManagementPorts()); $main->handle(); $inventory->doInventory(); //check data - $this->boolean($printer->getFromDB($printer->fields['id']))->isTrue(); - $this->integer($printer->fields['last_pages_counter'])->isIdenticalTo(1802); - $this->string($printer->fields['name'])->isIdenticalTo('NPIF2BE10'); + $this->assertTrue($printer->getFromDB($printer->fields['id'])); + $this->assertSame(1802, $printer->fields['last_pages_counter']); + $this->assertSame('NPIF2BE10', $printer->fields['name']); //second step do a standard discovery but change IP to update last page counter //GLPI allows the update @@ -1408,50 +1433,53 @@ public function testSnmpPrinterDiscoveryUpdateAllowed() $data = (array)$json->content; $inventory = new \Glpi\Inventory\Inventory(); - $this->boolean($inventory->setData($json))->isTrue(); + $this->assertTrue($inventory->setData($json)); $agent = new \Agent(); - $this->integer($agent->handleAgent($inventory->extractMetadata()))->isIdenticalTo(0); + $this->assertSame(0, $agent->handleAgent($inventory->extractMetadata())); $main = new \Glpi\Inventory\Asset\Printer($printer, $json); $main->setAgent($agent)->setExtraData($data); $main->checkConf(new \Glpi\Inventory\Conf()); $main->setDiscovery(true); $result = $main->prepare(); - $this->array($result)->hasSize(1); - $this->array((array)$result[0])->isIdenticalTo([ - 'autoupdatesystems_id' => 'GLPI Native Inventory', - 'last_inventory_update' => $date_now, - "is_deleted" => 0, - 'firmware' => '2409048_052887', - 'ips' => [$new_ip], - 'mac' => '00:68:eb:f2:be:10', - 'manufacturer' => 'Hewlett-Packard', - 'model' => 'HP LaserJet M507', - 'name' => $new_name, - 'serial' => 'PHCVN191TG', - 'type' => 'Printer', - 'uptime' => '7 days, 01:26:41.98', - 'printermodels_id' => 'HP LaserJet M507', - 'printertypes_id' => 'Printer', - 'manufacturers_id' => 'Hewlett-Packard', - 'snmpcredentials_id' => 4, - 'have_usb' => 0, - 'have_ethernet' => 1, - 'memory_size' => 512, - 'last_pages_counter' => 1802, - ]); - - $this->array($main->getNetworkPorts())->isIdenticalTo([]); + $this->assertCount(1, $result); + $this->assertSame( + [ + 'autoupdatesystems_id' => 'GLPI Native Inventory', + 'last_inventory_update' => $date_now, + "is_deleted" => 0, + 'firmware' => '2409048_052887', + 'ips' => [$new_ip], + 'mac' => '00:68:eb:f2:be:10', + 'manufacturer' => 'Hewlett-Packard', + 'model' => 'HP LaserJet M507', + 'name' => $new_name, + 'serial' => 'PHCVN191TG', + 'type' => 'Printer', + 'uptime' => '7 days, 01:26:41.98', + 'printermodels_id' => 'HP LaserJet M507', + 'printertypes_id' => 'Printer', + 'manufacturers_id' => 'Hewlett-Packard', + 'snmpcredentials_id' => 4, + 'have_usb' => 0, + 'have_ethernet' => 1, + 'memory_size' => 512, + 'last_pages_counter' => 1802, + ], + (array)$result[0] + ); + + $this->assertSame([], $main->getNetworkPorts()); //Since this -> https://github.com/glpi-project/glpi/pull/12197 //management port is not created if is known from port list of printer. - $this->array($main->getManagementPorts())->hasSize(0); + $this->assertCount(0, $main->getManagementPorts()); $main->handle(); $inventory->doInventory(); - $this->boolean($printer->getFromDB($printer->fields['id']))->isTrue(); - $this->string($printer->fields['name'])->isIdenticalTo($new_name); + $this->assertTrue($printer->getFromDB($printer->fields['id'])); + $this->assertSame($new_name, $printer->fields['name']); } public function testSnmpPrinterManagementPortCleaned() @@ -1548,68 +1576,72 @@ public function testSnmpPrinterManagementPortCleaned() $data = (array)$json->content; $inventory = new \Glpi\Inventory\Inventory(); - $this->boolean($inventory->setData($json))->isTrue(); + $this->assertTrue($inventory->setData($json)); $agent = new \Agent(); - $this->integer($agent->handleAgent($inventory->extractMetadata()))->isIdenticalTo(0); + $this->assertSame(0, $agent->handleAgent($inventory->extractMetadata())); $main = new \Glpi\Inventory\Asset\Printer($printer, $json); $main->setAgent($agent)->setExtraData($data); $main->checkConf(new \Glpi\Inventory\Conf()); $result = $main->prepare(); - $this->array($result)->hasSize(1); - $this->array((array)$result[0])->isIdenticalTo([ - 'autoupdatesystems_id' => 'GLPI Native Inventory', - 'last_inventory_update' => $date_now, - "is_deleted" => 0, - 'firmware' => '2409048_052887', - 'ips' => ['10.59.29.208', '0.0.0.0', '127.0.0.1'], - 'mac' => '00:68:eb:f2:be:10', - 'manufacturer' => 'Hewlett-Packard', - 'model' => 'CANON MP5353', - 'name' => 'NPIF2BE10', - 'serial' => 'PHCVN191TG', - 'type' => 'Printer', - 'uptime' => '7 days, 01:26:41.98', - 'printermodels_id' => 'CANON MP5353', - 'printertypes_id' => 'Printer', - 'manufacturers_id' => 'Hewlett-Packard', - 'snmpcredentials_id' => 4, - 'have_usb' => 0, - 'have_ethernet' => 1, - 'memory_size' => 512, - 'last_pages_counter' => 1802 - ]); + $this->assertCount(1, $result); + $this->assertSame( + [ + 'autoupdatesystems_id' => 'GLPI Native Inventory', + 'last_inventory_update' => $date_now, + "is_deleted" => 0, + 'firmware' => '2409048_052887', + 'ips' => ['10.59.29.208', '0.0.0.0', '127.0.0.1'], + 'mac' => '00:68:eb:f2:be:10', + 'manufacturer' => 'Hewlett-Packard', + 'model' => 'CANON MP5353', + 'name' => 'NPIF2BE10', + 'serial' => 'PHCVN191TG', + 'type' => 'Printer', + 'uptime' => '7 days, 01:26:41.98', + 'printermodels_id' => 'CANON MP5353', + 'printertypes_id' => 'Printer', + 'manufacturers_id' => 'Hewlett-Packard', + 'snmpcredentials_id' => 4, + 'have_usb' => 0, + 'have_ethernet' => 1, + 'memory_size' => 512, + 'last_pages_counter' => 1802 + ], + (array)$result[0] + ); //get no management port - $this->array($main->getManagementPorts())->hasSize(1); + $this->assertCount(1, $main->getManagementPorts()); //do real inventory to check dataDB $json = json_decode($json_str); $this->doInventory($json); $printer = new \Printer(); - $this->boolean($printer->getFromDbByCrit(['name' => 'NPIF2BE10', 'serial' => 'PHCVN191TG']))->isTrue(); + $this->assertTrue($printer->getFromDbByCrit(['name' => 'NPIF2BE10', 'serial' => 'PHCVN191TG'])); //1 NetworkPort $np = new \NetworkPort(); - $this->integer( + $this->assertSame( + 1, countElementsInTable( $np::getTable(), [['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortEthernet']] ) - )->isIdenticalTo(1); + ); //1 NetworkPortAggregate - $this->boolean($np->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate']))->isTrue(); + $this->assertTrue($np->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate'])); //1 NetworkName form NetworkPortAggregate $nm = new \NetworkName(); - $this->boolean($nm->getFromDbByCrit(["itemtype" => "NetworkPort", "items_id" => $np->fields['id']]))->isTrue(); + $this->assertTrue($nm->getFromDbByCrit(["itemtype" => "NetworkPort", "items_id" => $np->fields['id']])); //1 IPAdress form NetworkName $ip = new \IPAddress(); - $this->boolean($ip->getFromDbByCrit(["name" => "10.59.29.208", "itemtype" => "NetworkName", "items_id" => $nm->fields['id']]))->isTrue(); + $this->assertTrue($ip->getFromDbByCrit(["name" => "10.59.29.208", "itemtype" => "NetworkName", "items_id" => $nm->fields['id']])); //remove printer for other test $printer->delete($printer->fields); @@ -1663,8 +1695,8 @@ public function testSnmpPrinterManagementPortNotRecreated() if ($inventory->inError()) { $this->dump($inventory->getErrors()); } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isEmpty(); + $this->assertFalse($inventory->inError()); + $this->assertEmpty($inventory->getErrors()); //do a discovery $inventory->setDiscovery(true); @@ -1672,11 +1704,11 @@ public function testSnmpPrinterManagementPortNotRecreated() $printer = new \Printer(); - $this->boolean($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890']))->isTrue(); + $this->assertTrue($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890'])); //1 NetworkPortAggregate $np_aggregate = new \NetworkPort(); - $this->boolean($np_aggregate->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate']))->isTrue(); + $this->assertTrue($np_aggregate->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate'])); //redo a discovery @@ -1684,14 +1716,14 @@ public function testSnmpPrinterManagementPortNotRecreated() $inventory->doInventory($xml_source, true); $printer = new \Printer(); - $this->boolean($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890']))->isTrue(); + $this->assertTrue($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890'])); //1 NetworkPortAggregate $np_aggregate_after_reimport = new \NetworkPort(); - $this->boolean($np_aggregate_after_reimport->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate']))->isTrue(); + $this->assertTrue($np_aggregate_after_reimport->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate'])); - $this->integer($np_aggregate->fields['id'])->isEqualTo($np_aggregate_after_reimport->fields['id']); + $this->assertSame($np_aggregate_after_reimport->fields['id'], $np_aggregate->fields['id']); $xml_network_inventory = ' @@ -1801,28 +1833,28 @@ public function testSnmpPrinterManagementPortNotRecreated() $printer = new \Printer(); - $this->boolean($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890']))->isTrue(); + $this->assertTrue($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890'])); //1 NetworkPortAggregate $np_aggregate_after_networkinventory = new \NetworkPort(); - $this->boolean($np_aggregate_after_networkinventory->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate']))->isTrue(); + $this->assertTrue($np_aggregate_after_networkinventory->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate'])); - $this->integer($np_aggregate_after_reimport->fields['id'])->isEqualTo($np_aggregate_after_networkinventory->fields['id']); + $this->assertSame($np_aggregate_after_networkinventory->fields['id'], $np_aggregate_after_reimport->fields['id']); //redo an discovery $inventory->setDiscovery(true); $inventory->doInventory($xml_source, true); $printer = new \Printer(); - $this->boolean($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890']))->isTrue(); + $this->assertTrue($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890'])); //1 NetworkPortAggregate $np_aggregate_after_reimport = new \NetworkPort(); - $this->boolean($np_aggregate_after_reimport->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate']))->isTrue(); + $this->assertTrue($np_aggregate_after_reimport->getFromDbByCrit(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortAggregate'])); - $this->integer($np_aggregate_after_reimport->fields['id'])->isEqualTo($np_aggregate_after_reimport->fields['id']); + $this->assertSame($np_aggregate_after_reimport->fields['id'], $np_aggregate_after_reimport->fields['id']); //remove printer for other test $printer->delete($printer->fields); @@ -1900,8 +1932,8 @@ public function testSnmpPrinterNetworkPortNotRecreated() if ($inventory->inError()) { $this->dump($inventory->getErrors()); } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isEmpty(); + $this->assertFalse($inventory->inError()); + $this->assertEmpty($inventory->getErrors()); //do a inventory $inventory->setDiscovery(false); @@ -1909,12 +1941,12 @@ public function testSnmpPrinterNetworkPortNotRecreated() $printer = new \Printer(); - $this->boolean($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890']))->isTrue(); + $this->assertTrue($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890'])); //1 NetworkPortEthernet $np_ethernet = new \NetworkPort(); $np_ethernets = $np_ethernet->find(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortEthernet']); - $this->array($np_ethernets)->hasSize(1); + $this->assertCount(1, $np_ethernets); $first_np_versions = array_pop($np_ethernets); @@ -1923,16 +1955,16 @@ public function testSnmpPrinterNetworkPortNotRecreated() $inventory->doInventory($xml_source, true); $printer = new \Printer(); - $this->boolean($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890']))->isTrue(); + $this->assertTrue($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890'])); //1 NetworkPortEthernet $np_ethernet = new \NetworkPort(); $np_ethernets = $np_ethernet->find(['itemtype' => 'Printer', 'items_id' => $printer->fields['id'] , 'instantiation_type' => 'NetworkPortEthernet']); - $this->array($np_ethernets)->hasSize(1); + $this->assertCount(1, $np_ethernets); $second_np_versions = array_pop($np_ethernets); //check NetworkPort is same - $this->integer($second_np_versions['id'])->isIdenticalTo($first_np_versions['id']); + $this->assertSame($first_np_versions['id'], $second_np_versions['id']); //remove printer for other test $printer->delete($printer->fields); @@ -2011,16 +2043,16 @@ public function testSnmpPrinterAssetTag() if ($inventory->inError()) { $this->dump($inventory->getErrors()); } - $this->boolean($inventory->inError())->isFalse(); - $this->array($inventory->getErrors())->isEmpty(); + $this->assertFalse($inventory->inError()); + $this->assertEmpty($inventory->getErrors()); //do a inventory $inventory->doInventory($xml_source, true); $printer = new \Printer(); - $this->boolean($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890']))->isTrue(); + $this->assertTrue($printer->getFromDbByCrit(['name' => 'CLPSF99', 'serial' => 'E1234567890'])); - $this->string($printer->fields['otherserial'])->isIdenticalTo('other_serial'); + $this->assertSame('other_serial', $printer->fields['otherserial']); //remove printer for other test $printer->delete($printer->fields); diff --git a/tests/functional/Glpi/Inventory/Assets/Processor.php b/phpunit/functional/Glpi/Inventory/Assets/Processor.php similarity index 86% rename from tests/functional/Glpi/Inventory/Assets/Processor.php rename to phpunit/functional/Glpi/Inventory/Assets/Processor.php index 41db50895ab..bc3c757bcd8 100644 --- a/tests/functional/Glpi/Inventory/Assets/Processor.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Processor.php @@ -41,7 +41,7 @@ class Processor extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -111,7 +111,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\Processor($computer, $json->content->cpus); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -120,8 +120,10 @@ public function testHandle() //first, check there are no controller linked to this computer $idp = new \Item_DeviceProcessor(); - $this->boolean($idp->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A processor is already linked to computer!'); + $this->assertFalse( + $idp->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A processor is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -134,13 +136,15 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Processor($computer, $json->content->cpus); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($idp->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Processor has not been linked to computer :('); + $this->assertTrue( + $idp->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Processor has not been linked to computer :(' + ); } public function testInventoryUpdate() @@ -192,13 +196,13 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $manufacturer = new \Manufacturer(); $manufacturers_id = $manufacturer->add([ 'name' => 'Intel' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $cpu_1_id = $device_proc->add([ 'designation' => 'Intel(R) Core(TM) i9', @@ -206,14 +210,14 @@ public function testInventoryUpdate() 'frequence' => '2300', 'entities_id' => 0 ]); - $this->integer($cpu_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $cpu_1_id); $item_cpu_1_id = $item_proc->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'deviceprocessors_id' => $cpu_1_id ]); - $this->integer($item_cpu_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_cpu_1_id); $cpu_2_id = $device_proc->add([ 'designation' => 'Intel(R) Core(TM) i5', @@ -221,14 +225,14 @@ public function testInventoryUpdate() 'frequence' => '2000', 'entities_id' => 0 ]); - $this->integer($cpu_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $cpu_2_id); $item_cpu_2_id = $item_proc->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'deviceprocessors_id' => $cpu_2_id ]); - $this->integer($item_cpu_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_cpu_2_id); $cpu_3_id = $device_proc->add([ 'designation' => 'Intel(R) Core(TM) i3', @@ -236,19 +240,19 @@ public function testInventoryUpdate() 'frequence' => '1800', 'entities_id' => 0 ]); - $this->integer($cpu_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $cpu_3_id); $item_cpu_3_id = $item_proc->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'deviceprocessors_id' => $cpu_3_id ]); - $this->integer($item_cpu_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_cpu_3_id); $cpus = $item_proc->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($cpus))->isIdenticalTo(3); + $this->assertCount(3, $cpus); foreach ($cpus as $cpu) { - $this->variable($cpu['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $cpu['is_dynamic']); } //computer inventory knows only "i9" and "i5" processors @@ -256,19 +260,19 @@ public function testInventoryUpdate() //we still have 3 processors $cpus = $device_proc->find(); - $this->integer(count($cpus))->isIdenticalTo(3); + $this->assertCount(3, $cpus); //we still have 3 processors items linked to the computer $cpus = $item_proc->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($cpus))->isIdenticalTo(3); + $this->assertCount(3, $cpus); //processors present in the inventory source are now dynamic $cpus = $item_proc->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($cpus))->isIdenticalTo(2); + $this->assertCount(2, $cpus); //processor not present in the inventory is still not dynamic $cpus = $item_proc->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($cpus))->isIdenticalTo(1); + $this->assertCount(1, $cpus); //Redo inventory, but with removed "i5" processor $xml_source = " @@ -297,18 +301,18 @@ public function testInventoryUpdate() //we still have 3 processors $cpus = $device_proc->find(); - $this->integer(count($cpus))->isIdenticalTo(3); + $this->assertCount(3, $cpus); //we now have 2 processors linked to computer only $cpus = $item_proc->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($cpus))->isIdenticalTo(2); + $this->assertCount(2, $cpus); //processor present in the inventory source is still dynamic $cpus = $item_proc->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($cpus))->isIdenticalTo(1); + $this->assertCount(1, $cpus); //processor not present in the inventory is still not dynamic $cpus = $item_proc->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($cpus))->isIdenticalTo(1); + $this->assertCount(1, $cpus); } } diff --git a/tests/functional/Glpi/Inventory/Assets/RemoteManagement.php b/phpunit/functional/Glpi/Inventory/Assets/RemoteManagement.php similarity index 83% rename from tests/functional/Glpi/Inventory/Assets/RemoteManagement.php rename to phpunit/functional/Glpi/Inventory/Assets/RemoteManagement.php index 9737c44fdec..abd4df8a419 100644 --- a/tests/functional/Glpi/Inventory/Assets/RemoteManagement.php +++ b/phpunit/functional/Glpi/Inventory/Assets/RemoteManagement.php @@ -41,7 +41,7 @@ class RemoteManagement extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -103,18 +103,16 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\RemoteManagement($computer, $json->content->remote_mgmt); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testWrongMainItem() { $mainasset = getItemByTypeName('Printer', '_test_printer_all'); $asset = new \Glpi\Inventory\Asset\RemoteManagement($mainasset); - $this->exception( - function () use ($asset) { - $asset->prepare(); - } - )->message->contains('Remote Management are handled for following types only:'); + + $this->expectExceptionMessage('Remote Management are handled for following types only:'); + $asset->prepare(); } public function testHandle() @@ -122,17 +120,18 @@ public function testHandle() global $DB; $computer = getItemByTypeName('Computer', '_test_pc01'); - //first, check there are no remote management linked to this computer + //first, check there are no remote management linked to this computer $mgmt = new \Item_RemoteManagement(); - $this->boolean( + $this->assertFalse( $mgmt->getFromDbByCrit([ 'itemtype' => $computer->getType(), 'items_id' => $computer->fields['id'] - ]) - )->isFalse('An remote management is already linked to computer!'); + ]), + 'A remote management is already linked to computer!' + ); - //convert data - $expected = $this->assetProvider()[0]; + //convert data + $expected = $this::assetProvider()[0]; $converter = new \Glpi\Inventory\Converter(); $data = $converter->convert($expected['xml']); @@ -141,18 +140,19 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\RemoteManagement($computer, $json->content->remote_mgmt); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean( + $this->assertTrue( $mgmt->getFromDbByCrit([ 'itemtype' => $computer->getType(), 'items_id' => $computer->fields['id'] - ]) - )->isTrue('Remote Management has not been linked to computer :('); + ]), + 'Remote Management has not been linked to computer :(' + ); } public function testUpdate() @@ -163,14 +163,15 @@ public function testUpdate() //first, check there are no remote management linked to this computer $mgmt = new \Item_RemoteManagement(); - $this->boolean( + $this->assertTrue( $mgmt->getFromDbByCrit([ 'itemtype' => $computer->getType(), 'items_id' => $computer->fields['id'] - ]) - )->isTrue('No remote management linked to computer!'); + ]), + 'No remote management linked to computer!' + ); - $expected = $this->assetProvider()[0]; + $expected = $this::assetProvider()[0]; $json_expected = json_decode($expected['expected']); $xml = $expected['xml']; //change version @@ -184,18 +185,18 @@ public function testUpdate() $asset = new \Glpi\Inventory\Asset\RemoteManagement($computer, $json->content->remote_mgmt); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo($json_expected); + $this->assertEquals($json_expected, $result[0]); $asset->handleLinks(); $asset->handle(); - $this->boolean( + $this->assertTrue( $mgmt->getFromDbByCrit([ 'itemtype' => $computer->getType(), 'items_id' => $computer->fields['id'] ]) - )->isTrue(); + ); - $this->string($mgmt->fields['remoteid'])->isIdenticalTo('987654321'); + $this->assertSame('987654321', $mgmt->fields['remoteid']); } public function testInventoryUpdate() @@ -232,39 +233,42 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); - $this->integer( + $this->assertGreaterThan( + 0, $mgmt->add([ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'type' => 'teamviewer', 'remoteid' => '123456789' ]) - )->isGreaterThan(0); + ); - $this->integer( + $this->assertGreaterThan( + 0, $mgmt->add([ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'type' => 'anydesk', 'remoteid' => 'abcdyz' ]) - )->isGreaterThan(0); + ); - $this->integer( + $this->assertGreaterThan( + 0, $mgmt->add([ 'itemtype' => 'Computer', 'items_id' => $computers_id, 'type' => 'mymgmt', 'remoteid' => 'qwertyuiop' ]) - )->isGreaterThan(0); + ); $mgmts = $mgmt->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($mgmts))->isIdenticalTo(3); + $this->assertCount(3, $mgmts); foreach ($mgmts as $m) { - $this->variable($m['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $m['is_dynamic']); } //computer inventory knows only "teamviewer" and "anydesk" remote managements @@ -272,19 +276,19 @@ public function testInventoryUpdate() //we still have 3 remote managements $mgmts = $mgmt->find(); - $this->integer(count($mgmts))->isIdenticalTo(3); + $this->assertCount(3, $mgmts); //we still have 3 remote managements items linked to the computer $mgmts = $mgmt->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($mgmts))->isIdenticalTo(3); + $this->assertCount(3, $mgmts); //remote managements present in the inventory source are now dynamic $mgmts = $mgmt->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($mgmts))->isIdenticalTo(2); + $this->assertCount(2, $mgmts); //remote management not present in the inventory is still not dynamic $mgmts = $mgmt->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($mgmts))->isIdenticalTo(1); + $this->assertCount(1, $mgmts); //Redo inventory, but with removed "anydesk" remote managements $xml_source = " @@ -310,19 +314,19 @@ public function testInventoryUpdate() //we now have only 2 remote managements $mgmts = $mgmt->find(); - $this->integer(count($mgmts))->isIdenticalTo(2); + $this->assertCount(2, $mgmts); //we now have 2 remote managements linked to computer only $mgmts = $mgmt->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($mgmts))->isIdenticalTo(2); + $this->assertCount(2, $mgmts); //remote management present in the inventory source is still dynamic $mgmts = $mgmt->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($mgmts))->isIdenticalTo(1); + $this->assertCount(1, $mgmts); //remote management not present in the inventory is still not dynamic $mgmts = $mgmt->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($mgmts))->isIdenticalTo(1); + $this->assertCount(1, $mgmts); } public function testNoMoreRemoteManagement() @@ -353,7 +357,7 @@ public function testNoMoreRemoteManagement() //we have 1 remote managements (anydesk / abcdyz) linked to computer $mgmts = $mgmt->find(); - $this->integer(count($mgmts))->isIdenticalTo(1); + $this->assertCount(1, $mgmts); $xml_source = " @@ -374,6 +378,6 @@ public function testNoMoreRemoteManagement() //we have no remote managements linked to computer $mgmts = $mgmt->find(); - $this->integer(count($mgmts))->isIdenticalTo(0); + $this->assertCount(0, $mgmts); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Sensor.php b/phpunit/functional/Glpi/Inventory/Assets/Sensor.php similarity index 84% rename from tests/functional/Glpi/Inventory/Assets/Sensor.php rename to phpunit/functional/Glpi/Inventory/Assets/Sensor.php index 4f076b68fe1..0d0b59d2e70 100644 --- a/tests/functional/Glpi/Inventory/Assets/Sensor.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Sensor.php @@ -41,7 +41,7 @@ class Sensor extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -95,7 +95,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\Sensor($computer, $json->content->sensors); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -104,8 +104,10 @@ public function testHandle() //first, check there are no sensor linked to this computer $ids = new \Item_DeviceSensor(); - $this->boolean($ids->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A sensor is already linked to computer!'); + $this->assertFalse( + $ids->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A sensor is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -118,13 +120,15 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\Sensor($computer, $json->content->sensors); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($ids->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Sensor has not been linked to computer :('); + $this->assertTrue( + $ids->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Sensor has not been linked to computer :(' + ); } public function testInventoryUpdate() @@ -168,19 +172,19 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $manufacturer = new \Manufacturer(); $manufacturers_id = $manufacturer->add([ 'name' => 'STMicroelectronics' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $type = new \DeviceSensorType(); $types_id = $type->add([ 'name' => 'ACCELEROMETER' ]); - $this->integer($types_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $types_id); $sensor_1_id = $device_sensor->add([ 'designation' => 'LSM330DLC 3-axis Accelerometer', @@ -189,24 +193,24 @@ public function testInventoryUpdate() 'locations_id' => 0, 'entities_id' => 0 ]); - $this->integer($sensor_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $sensor_1_id); $item_sensor_1_id = $item_sensor->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicesensors_id' => $sensor_1_id ]); - $this->integer($item_sensor_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_sensor_1_id); $manufacturers_id = $manufacturer->add([ 'name' => 'Asahi Kasei Microdevices' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $types_id = $type->add([ 'name' => 'MAGNETIC FIELD' ]); - $this->integer($types_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $types_id); $sensor_2_id = $device_sensor->add([ 'designation' => 'AK8975C 3-axis Magnetic field sensor', @@ -216,14 +220,14 @@ public function testInventoryUpdate() 'entities_id' => 0 ]); - $this->integer($sensor_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $sensor_2_id); $item_sensor_2_id = $item_sensor->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicesensors_id' => $sensor_2_id ]); - $this->integer($item_sensor_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_sensor_2_id); $sensor_3_id = $device_sensor->add([ 'designation' => 'TMG399X RGB Sensor', @@ -232,19 +236,19 @@ public function testInventoryUpdate() 'locations_id' => 0, 'entities_id' => 0 ]); - $this->integer($sensor_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $sensor_3_id); $item_sensor_3_id = $item_sensor->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicesensors_id' => $sensor_3_id ]); - $this->integer($item_sensor_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_sensor_3_id); $sensors = $item_sensor->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($sensors))->isIdenticalTo(3); + $this->assertCount(3, $sensors); foreach ($sensors as $sensor) { - $this->variable($sensor['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $sensor['is_dynamic']); } //computer inventory knows only "LSM330DLC" and "AK8975C" sensors @@ -252,19 +256,19 @@ public function testInventoryUpdate() //we still have 3 sensors (+ 1 from bootstrap) $sensors = $device_sensor->find(); - $this->integer(count($sensors))->isIdenticalTo(3 + 1); + $this->assertCount(3 + 1, $sensors); //we still have 3 sensors items linked to the computer $sensors = $item_sensor->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($sensors))->isIdenticalTo(3); + $this->assertCount(3, $sensors); //sensors present in the inventory source are now dynamic $sensors = $item_sensor->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($sensors))->isIdenticalTo(2); + $this->assertCount(2, $sensors); //sensor not present in the inventory is still not dynamic $sensors = $item_sensor->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($sensors))->isIdenticalTo(1); + $this->assertCount(1, $sensors); //Redo inventory, but with removed "AK8975C" sensor $xml_source = " @@ -293,18 +297,18 @@ public function testInventoryUpdate() //we still have 3 sensors (+1 from bootstrap) $sensors = $device_sensor->find(); - $this->integer(count($sensors))->isIdenticalTo(3 + 1); + $this->assertCount(3 + 1, $sensors); //we now have 2 sensors linked to computer only $sensors = $item_sensor->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($sensors))->isIdenticalTo(2); + $this->assertCount(2, $sensors); //sensor present in the inventory source is still dynamic $sensors = $item_sensor->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($sensors))->isIdenticalTo(1); + $this->assertCount(1, $sensors); //sensor not present in the inventory is still not dynamic $sensors = $item_sensor->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($sensors))->isIdenticalTo(1); + $this->assertCount(1, $sensors); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Software.php b/phpunit/functional/Glpi/Inventory/Assets/SoftwareTest.php similarity index 79% rename from tests/functional/Glpi/Inventory/Assets/Software.php rename to phpunit/functional/Glpi/Inventory/Assets/SoftwareTest.php index 7f9dd0d14bc..fb4ae1869db 100644 --- a/tests/functional/Glpi/Inventory/Assets/Software.php +++ b/phpunit/functional/Glpi/Inventory/Assets/SoftwareTest.php @@ -41,9 +41,9 @@ /* Test for inc/inventory/asset/computer.class.php */ -class Software extends AbstractInventoryAsset +class SoftwareTest extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -120,7 +120,7 @@ public function testPrepare($xml, $expected) //Manufacturer has been imported into db... $expected = json_decode($expected); - $this->object($result[0])->isEqualTo($expected); + $this->assertEquals($expected, $result[0]); } public function testHandle() @@ -130,11 +130,13 @@ public function testHandle() //first, check there are no software linked to this computer $sov = new \Item_SoftwareVersion(); - $this->boolean($sov->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A software version is already linked to computer!'); + $this->assertFalse( + $sov->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A software version is already linked to computer!' + ); //convert data - $expected = $this->assetProvider()[0]; + $expected = $this::assetProvider()[0]; $converter = new \Glpi\Inventory\Converter(); $data = $converter->convert($expected['xml']); @@ -149,20 +151,22 @@ public function testHandle() $result = $asset->prepare(); $expected = json_decode($expected['expected']); - $this->object($result[0])->isEqualTo($expected); + $this->assertEquals($expected, $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($sov->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('A software version has not been linked to computer!'); + $this->assertTrue( + $sov->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A software version has not been linked to computer!' + ); $version = new \SoftwareVersion(); - $this->boolean($version->getFromDB($sov->fields['softwareversions_id']))->isTrue(); - $this->integer($version->fields['operatingsystems_id'])->isIdenticalTo(0); // no OS from $this->assetProvider()[0]; + $this->assertTrue($version->getFromDB($sov->fields['softwareversions_id'])); + $this->assertSame(0, $version->fields['operatingsystems_id']); // no OS from $this::assetProvider()[0]; //convert data - $expected = $this->assetProvider()[1]; + $expected = $this::assetProvider()[1]; $converter = new \Glpi\Inventory\Converter(); $data = $converter->convert($expected['xml']); @@ -182,35 +186,39 @@ public function testHandle() $asset->setExtraData($extra_data); $result = $asset->prepare(); $expected = json_decode($expected['expected']); - $this->object($result[0])->isEqualTo($expected); + $this->assertEquals($expected, $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($sov->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer', ['NOT' => ['date_install' => null]]])) - ->isTrue('A software version has not been linked to computer!'); + $this->assertTrue( + $sov->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer', ['NOT' => ['date_install' => null]]]), + 'A software version has not been linked to computer!' + ); - $this->integer($sov->fields['softwareversions_id'])->isNotEqualTo($version->fields['id']); + $this->assertNotEquals($version->fields['id'], $sov->fields['softwareversions_id']); $ios = new \Item_OperatingSystem(); - $this->boolean($ios->getFromDBByCrit([ + $this->assertTrue($ios->getFromDBByCrit([ "itemtype" => 'Computer', "items_id" => $computer->fields['id'] - ]))->isTrue(); + ])); $version = new \SoftwareVersion(); - $this->boolean($version->getFromDB($sov->fields['softwareversions_id']))->isTrue(); - $this->integer($version->fields['operatingsystems_id'])->isEqualTo($ios->fields['operatingsystems_id']); //check linked OS from SoftwareVersion + $this->assertTrue($version->getFromDB($sov->fields['softwareversions_id'])); + $this->assertSame($ios->fields['operatingsystems_id'], $version->fields['operatingsystems_id']); //check linked OS from SoftwareVersion //new computer with same software global $DB; $soft_reference = $DB->request(\Software::getTable()); - $this->integer(count($soft_reference))->isIdenticalTo(5); + $this->assertCount(5, $soft_reference); $computer2 = getItemByTypeName('Computer', '_test_pc02'); //first, check there are no software linked to this computer - $this->boolean($sov->getFromDbByCrit(['items_id' => $computer2->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A software version is already linked to computer!'); + $this->assertFalse( + $sov->getFromDbByCrit(['items_id' => $computer2->fields['id'], 'itemtype' => 'Computer']), + 'A software version is already linked to computer!' + ); $asset = new \Glpi\Inventory\Asset\Software($computer2, $json->content->softwares); $osasset = new \Glpi\Inventory\Asset\OperatingSystem($computer2, (array)$json->content->operatingsystem); @@ -228,10 +236,12 @@ public function testHandle() //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($sov->getFromDbByCrit(['items_id' => $computer2->fields['id'], 'itemtype' => 'Computer', ['NOT' => ['date_install' => null]]])) - ->isTrue('A software version has not been linked to computer!'); + $this->assertTrue( + $sov->getFromDbByCrit(['items_id' => $computer2->fields['id'], 'itemtype' => 'Computer', ['NOT' => ['date_install' => null]]]), + 'A software version has not been linked to computer!' + ); - $this->integer(count($DB->request(\Software::getTable())))->isIdenticalTo(count($soft_reference)); + $this->assertCount(count($soft_reference), $DB->request(\Software::getTable())); } public function testInventoryUpdate() @@ -286,16 +296,16 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); //computer inventory knows only "gimp" and "php-cli" software $this->doInventory($xml_source, true); //we have 2 software & versions $softs = $soft->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($softs))->isIdenticalTo(2); + $this->assertCount(2, $softs); $versions = $version->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($versions))->isIdenticalTo(2); + $this->assertCount(2, $versions); //check that sofware exist with softwarecategories $criteria = [ @@ -315,7 +325,7 @@ public function testInventoryUpdate() ]; $iterator = $DB->request($criteria); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); $criteria = [ 'FROM' => \Software::getTable(), @@ -334,15 +344,15 @@ public function testInventoryUpdate() ]; $iterator = $DB->request($criteria); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); //we have 2 softwareversion items linked to the computer $item_versions = $item_version->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($item_versions))->isIdenticalTo(2); + $this->assertCount(2, $item_versions); //software present in the inventory source are dynamic $item_versions = $item_version->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($item_versions))->isIdenticalTo(2); + $this->assertCount(2, $item_versions); //Redo inventory, but with removed "php-cli" software and change softwareCategories $xml_source = " @@ -375,12 +385,12 @@ public function testInventoryUpdate() //we still have 2 software & versions $softs = $soft->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($softs))->isIdenticalTo(2); + $this->assertCount(2, $softs); $versions = $version->find(['NOT' => ['name' => ['LIKE', '_test_%']]]); - $this->integer(count($versions))->isIdenticalTo(2); + $this->assertCount(2, $versions); $categories_iterator = $DB->request(['FROM' => \SoftwareCategory::getTable()]); - $this->integer(count($categories_iterator))->isIdenticalTo(4); + $this->assertCount(4, $categories_iterator); //check that software still exist but with different softwarecategories $criteria = [ @@ -399,15 +409,15 @@ public function testInventoryUpdate() ] ]; $iterator = $DB->request($criteria); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); //we now have 1 softwareversion items linked to the computer $item_versions = $item_version->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($item_versions))->isIdenticalTo(1); + $this->assertCount(1, $item_versions); //software present in the inventory source is still dynamic $item_versions = $item_version->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($item_versions))->isIdenticalTo(1); + $this->assertCount(1, $item_versions); } @@ -440,21 +450,27 @@ public function testSoftwareEntity() 'is_recursive' => 1, 'ranking' => 1, ]); - $this->integer((int) $rules_id)->isGreaterThan(0); - - $this->integer((int) $rulecriteria->add([ - 'rules_id' => $rules_id, - 'criteria' => "tag", - 'pattern' => "/(.*)/", - 'condition' => \RuleImportEntity::REGEX_MATCH - ]))->isGreaterThan(0); - - $this->integer((int) $ruleaction->add([ - 'rules_id' => $rules_id, - 'action_type' => 'regex_result', - 'field' => '_affect_entity_by_tag', - 'value' => 'testtag_2', - ]))->isGreaterThan(0); + $this->assertGreaterThan(0, (int) $rules_id); + + $this->assertGreaterThan( + 0, + (int) $rulecriteria->add([ + 'rules_id' => $rules_id, + 'criteria' => "tag", + 'pattern' => "/(.*)/", + 'condition' => \RuleImportEntity::REGEX_MATCH + ]) + ); + + $this->assertGreaterThan( + 0, + (int) $ruleaction->add([ + 'rules_id' => $rules_id, + 'action_type' => 'regex_result', + 'field' => '_affect_entity_by_tag', + 'value' => 'testtag_2', + ]) + ); $xml_source = " @@ -490,16 +506,16 @@ public function testSoftwareEntity() $computer = new \Computer(); $found_computers = $computer->find(['name' => "pc_test_entity"]); - $this->integer(count($found_computers))->isIdenticalTo(1); + $this->assertCount(1, $found_computers); $first_computer = array_pop($found_computers); - $this->integer($first_computer['entities_id'])->isIdenticalTo($entity_2_id); + $this->assertSame($entity_2_id, $first_computer['entities_id']); $soft = new \Software(); $softs = $soft->find(['name' => "test_software"]); - $this->integer(count($softs))->isIdenticalTo(1); + $this->assertCount(1, $softs); $first_soft = array_pop($softs); - $this->integer($first_soft['entities_id'])->isIdenticalTo($entity_2_id); - $this->integer($first_soft['is_recursive'])->isIdenticalTo(0); + $this->assertSame($entity_2_id, $first_soft['entities_id']); + $this->assertSame(0, $first_soft['is_recursive']); } public function testSoftwareWithSpecialChar() @@ -538,24 +554,24 @@ public function testSoftwareWithSpecialChar() $computer = new \Computer(); $found_computers = $computer->find(['name' => "pc_test_entity"]); - $this->integer(count($found_computers))->isIdenticalTo(1); + $this->assertCount(1, $found_computers); $first_computer = array_pop($found_computers); $soft = new \Software(); $softs = $soft->find(['name' => "ភាសាខ្មែរ កញ្ចប់បទពិសោធន៍ផ្ទៃក្នុង"]); - $this->integer(count($softs))->isIdenticalTo(1); + $this->assertCount(1, $softs); $computer_softversion = new \Item_SoftwareVersion(); $computer_softversions = $computer_softversion->find([ 'itemtype' => "Computer", 'items_id' => $first_computer['id'] ]); - $this->integer(count($computer_softversions))->isIdenticalTo(1); + $this->assertCount(1, $computer_softversions); $first_computer_soft = array_pop($computer_softversions); $version = new SoftwareVersion(); - $this->boolean($version->getFromDB($first_computer_soft['softwareversions_id']))->isTrue(); - $this->string($version->fields['name'])->isEqualTo("1.1"); + $this->assertTrue($version->getFromDB($first_computer_soft['softwareversions_id'])); + $this->assertEquals("1.1", $version->fields['name']); //update software version $xml_source = " @@ -592,24 +608,24 @@ public function testSoftwareWithSpecialChar() $computer = new \Computer(); $found_computers = $computer->find(['name' => "pc_test_entity"]); - $this->integer(count($found_computers))->isIdenticalTo(1); + $this->assertCount(1, $found_computers); $first_computer = array_pop($found_computers); $soft = new \Software(); $softs = $soft->find(['name' => "ភាសាខ្មែរ កញ្ចប់បទពិសោធន៍ផ្ទៃក្នុង"]); - $this->integer(count($softs))->isIdenticalTo(1); + $this->assertCount(1, $softs); $computer_softversion = new \Item_SoftwareVersion(); $computer_softversions = $computer_softversion->find([ 'itemtype' => "Computer", 'items_id' => $first_computer['id'] ]); - $this->integer(count($computer_softversions))->isIdenticalTo(1); + $this->assertCount(1, $computer_softversions); $first_computer_soft = array_pop($computer_softversions); $version = new SoftwareVersion(); - $this->boolean($version->getFromDB($first_computer_soft['softwareversions_id']))->isTrue(); - $this->string($version->fields['name'])->isEqualTo("1.4"); + $this->assertTrue($version->getFromDB($first_computer_soft['softwareversions_id'])); + $this->assertEquals("1.4", $version->fields['name']); } public function testSoftwareRuledictionnaryManufacturer() @@ -628,21 +644,27 @@ public function testSoftwareRuledictionnaryManufacturer() 'is_recursive' => 1, 'ranking' => 1, ]); - $this->integer((int) $rules_id)->isGreaterThan(0); - - $this->integer((int) $rulecriteria->add([ - 'rules_id' => $rules_id, - 'criteria' => "name", - 'pattern' => "Microsoft", - 'condition' => \Rule::PATTERN_CONTAIN - ]))->isGreaterThan(0); - - $this->integer((int) $ruleaction->add([ - 'rules_id' => $rules_id, - 'action_type' => 'assign', - 'field' => 'name', - 'value' => 'Personal_Publisher', - ]))->isGreaterThan(0); + $this->assertGreaterThan(0, (int) $rules_id); + + $this->assertGreaterThan( + 0, + (int) $rulecriteria->add([ + 'rules_id' => $rules_id, + 'criteria' => "name", + 'pattern' => "Microsoft", + 'condition' => \Rule::PATTERN_CONTAIN + ]) + ); + + $this->assertGreaterThan( + 0, + (int) $ruleaction->add([ + 'rules_id' => $rules_id, + 'action_type' => 'assign', + 'field' => 'name', + 'value' => 'Personal_Publisher', + ]) + ); $xml_source = " @@ -678,17 +700,17 @@ public function testSoftwareRuledictionnaryManufacturer() $computer = new \Computer(); $found_computers = $computer->find(['name' => "pc_test_entity"]); - $this->integer(count($found_computers))->isIdenticalTo(1); + $this->assertCount(1, $found_computers); $soft = new \Software(); $softs = $soft->find(['name' => "test_software"]); - $this->integer(count($softs))->isIdenticalTo(1); + $this->assertCount(1, $softs); $first_soft = array_pop($softs); $manufacturer = new \Manufacturer(); $manufacturer->getFromDB($first_soft['manufacturers_id']); - $this->string($manufacturer->fields['name'])->isEqualTo('Personal_Publisher'); + $this->assertEquals('Personal_Publisher', $manufacturer->fields['name']); } public function testSoftwareRuledictionnarySoftware() @@ -707,22 +729,27 @@ public function testSoftwareRuledictionnarySoftware() 'is_recursive' => 1, 'ranking' => 1, ]); - $this->integer((int) $rules_id)->isGreaterThan(0); - - $this->integer((int) $rulecriteria->add([ - 'rules_id' => $rules_id, - 'criteria' => "manufacturer", - 'pattern' => "Apple", - 'condition' => \Rule::PATTERN_CONTAIN - ]))->isGreaterThan(0); - - $this->integer((int) $ruleaction->add([ - 'rules_id' => $rules_id, - 'action_type' => 'assign', - 'field' => 'manufacturer', - 'value' => 'Other_Publisher', - ]))->isGreaterThan(0); - + $this->assertGreaterThan(0, (int) $rules_id); + + $this->assertGreaterThan( + 0, + (int) $rulecriteria->add([ + 'rules_id' => $rules_id, + 'criteria' => "manufacturer", + 'pattern' => "Apple", + 'condition' => \Rule::PATTERN_CONTAIN + ]) + ); + + $this->assertGreaterThan( + 0, + (int) $ruleaction->add([ + 'rules_id' => $rules_id, + 'action_type' => 'assign', + 'field' => 'manufacturer', + 'value' => 'Other_Publisher', + ]) + ); $xml_source = " @@ -758,31 +785,31 @@ public function testSoftwareRuledictionnarySoftware() $computer = new \Computer(); $found_computers = $computer->find(['name' => "pc_test_entity"]); - $this->integer(count($found_computers))->isIdenticalTo(1); + $this->assertCount(1, $found_computers); $soft = new \Software(); $softs = $soft->find(['name' => "test_software"]); - $this->integer(count($softs))->isIdenticalTo(1); + $this->assertCount(1, $softs); $first_soft = array_pop($softs); $manufacturer = new \Manufacturer(); $manufacturer->getFromDB($first_soft['manufacturers_id']); - $this->string($manufacturer->fields['name'])->isEqualTo('Other_Publisher'); + $this->assertEquals('Other_Publisher', $manufacturer->fields['name']); } - protected function softwareProvider(): array + public static function softwareProvider(): array { return [ //To test FullCompareKey (with special chars on software name / manufacturer) - '/tests/fixtures/inventories/softwares/01-test_software_with_special_chars_with_version.json', - '/tests/fixtures/inventories/softwares/02-test_software_with_special_chars_with_version.json', + ['/tests/fixtures/inventories/softwares/01-test_software_with_special_chars_with_version.json'], + ['/tests/fixtures/inventories/softwares/02-test_software_with_special_chars_with_version.json'], //To test FullCompareKey without version (with special chars on software name / manufacturer) - '/tests/fixtures/inventories/softwares/03-test_software_with_special_chars_and_without_version.json', + ['/tests/fixtures/inventories/softwares/03-test_software_with_special_chars_and_without_version.json'], // /To test FullCompareKey with version (with special chars on software name / manufacturer name / OS name / arch name) - '/tests/fixtures/inventories/softwares/04-test_software_with_special_chars_and_with_version_and_os.json', + ['/tests/fixtures/inventories/softwares/04-test_software_with_special_chars_and_with_version_and_os.json'], // /To test FullCompareKey without version (with special chars on software name / manufacturer name / OS name / arch name) - '/tests/fixtures/inventories/softwares/05-test_software_with_special_chars_and_without_version_and_os.json', + ['/tests/fixtures/inventories/softwares/05-test_software_with_special_chars_and_without_version_and_os.json'], ]; } @@ -797,7 +824,7 @@ public function testSoftwareWithHtmlentites($path) $computer = new \Computer(); $found_computers = $computer->find(['name' => "pc_test"]); - $this->integer(count($found_computers))->isIdenticalTo(1); + $this->assertCount(1, $found_computers); $first_computer = array_pop($found_computers); //get Software / ItemSoftware @@ -806,15 +833,15 @@ public function testSoftwareWithHtmlentites($path) $software_item = new \Item_SoftwareVersion(); $software_items = $software_item->find(['itemtype' => "Computer", "items_id" => $first_computer['id']]); - $this->integer(count($software_items))->isIdenticalTo(1); + $this->assertCount(1, $software_items); $first_software_items = array_pop($software_items); $software_versions = $software_version->find(['id' => $first_software_items['softwareversions_id']]); - $this->integer(count($software_versions))->isIdenticalTo(1); + $this->assertCount(1, $software_versions); $first_software_versions = array_pop($software_versions); $softwares = $software->find(['id' => $first_software_versions['softwares_id']]); - $this->integer(count($softwares))->isIdenticalTo(1); + $this->assertCount(1, $softwares); $first_software = array_pop($softwares); @@ -824,25 +851,25 @@ public function testSoftwareWithHtmlentites($path) $computer = new \Computer(); $found_computers = $computer->find(['name' => "pc_test"]); - $this->integer(count($found_computers))->isIdenticalTo(1); + $this->assertCount(1, $found_computers); $first_computer = array_pop($found_computers); $software_items = $software_item->find(['itemtype' => "Computer", "items_id" => $first_computer['id']]); - $this->integer(count($software_items))->isIdenticalTo(1); + $this->assertCount(1, $software_items); $second_software_items = array_pop($software_items); $software_versions = $software_version->find(['id' => $second_software_items['softwareversions_id']]); - $this->integer(count($software_versions))->isIdenticalTo(1); + $this->assertCount(1, $software_versions); $second_software_versions = array_pop($software_versions); $softwares = $software->find(['id' => $second_software_versions['softwares_id']]); - $this->integer(count($softwares))->isIdenticalTo(1); + $this->assertCount(1, $softwares); $second_software = array_pop($softwares); - $this->integer($second_software_items['id'])->isIdenticalTo($first_software_items['id']); - $this->integer($second_software_versions['id'])->isIdenticalTo($first_software_versions['id']); - $this->integer($second_software['id'])->isIdenticalTo($first_software['id']); + $this->assertSame($first_software_items['id'], $second_software_items['id']); + $this->assertSame($first_software_versions['id'], $second_software_versions['id']); + $this->assertSame($first_software['id'], $second_software['id']); $computer->deleteByCriteria(['id' => $first_computer['id']]); } @@ -891,27 +918,27 @@ public function testDuplicatedSoft() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $this->doInventory($xml_source, true); $manufacturer = new \Manufacturer(); - $this->boolean($manufacturer->getFromDBByCrit(['name' => 'Microsoft Corporation']))->isTrue(); + $this->assertTrue($manufacturer->getFromDBByCrit(['name' => 'Microsoft Corporation'])); //we have 1 software & versions for Microsoft Office Standard - Microsoft Corporation $softs = $soft->find(['name' => 'Microsoft Office Standard 2013', 'manufacturers_id' => $manufacturer->fields['id']]); - $this->integer(count($softs))->isIdenticalTo(1); + $this->assertCount(1, $softs); //15.0.4569.1506 $versions = $version->find(['name' => '15.0.4569.1506']); - $this->integer(count($versions))->isIdenticalTo(1); + $this->assertCount(1, $versions); $version_data = array_pop($versions); - $this->boolean($item_version->getFromDBByCrit([ + $this->assertTrue($item_version->getFromDBByCrit([ "itemtype" => "Computer", "items_id" => $computers_id, "softwareversions_id" => $version_data['id'] - ]))->isTrue(); + ])); //inventory with two same software: one with name containing an unbreakable space, the other with standard space $xml_source = " @@ -1015,24 +1042,24 @@ public function testSameSoft() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $this->doInventory($xml_source, true); //we have 1 software & versions for Cisco AnyConnect Secure Mobility Client $softs = $soft->find(['name' => 'Cisco AnyConnect Secure Mobility Client']); - $this->integer(count($softs))->isIdenticalTo(1); + $this->assertCount(1, $softs); //4.10.01075 $versions = $version->find(['name' => '4.10.01075']); - $this->integer(count($versions))->isIdenticalTo(1); + $this->assertCount(1, $versions); $version_data = array_pop($versions); - $this->boolean($item_version->getFromDBByCrit([ + $this->assertTrue($item_version->getFromDBByCrit([ "itemtype" => "Computer", "items_id" => $computers_id, "softwareversions_id" => $version_data['id'] - ]))->isTrue(); + ])); //inventory with Cisco soft updated $xml_source = " @@ -1082,18 +1109,18 @@ public function testSameSoft() //we have 1 software & versions for Cisco AnyConnect Secure Mobility Client $softs = $soft->find(['name' => 'Cisco AnyConnect Secure Mobility Client']); - $this->integer(count($softs))->isIdenticalTo(1); + $this->assertCount(1, $softs); //4.10.06079 $versions = $version->find(['name' => '4.10.06079']); - $this->integer(count($versions))->isIdenticalTo(1); + $this->assertCount(1, $versions); $version_data = array_pop($versions); - $this->boolean($item_version->getFromDBByCrit([ + $this->assertTrue($item_version->getFromDBByCrit([ "itemtype" => "Computer", "items_id" => $computers_id, "softwareversions_id" => $version_data['id'] - ]))->isTrue(); + ])); } public function testSameSoftManufacturer() @@ -1139,42 +1166,42 @@ public function testSameSoftManufacturer() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $this->doInventory($xml_source, true); //we have 1 software & versions for ÀVEVA Application Server 2020 $softs = $soft->find(['name' => 'ÀVEVA Application Server 2020']); - $this->integer(count($softs))->isIdenticalTo(1); + $this->assertCount(1, $softs); //20.0.000 $versions = $version->find(['name' => '20.0.000']); - $this->integer(count($versions))->isIdenticalTo(1); + $this->assertCount(1, $versions); $version_data = array_pop($versions); - $this->boolean($item_version->getFromDBByCrit([ + $this->assertTrue($item_version->getFromDBByCrit([ "itemtype" => "Computer", "items_id" => $computers_id, "softwareversions_id" => $version_data['id'] - ]))->isTrue(); + ])); //same inventory again $this->doInventory($xml_source, true); //we have 1 software & versions for ÀVEVA Application Server 2020 $softs = $soft->find(['name' => 'ÀVEVA Application Server 2020']); - $this->integer(count($softs))->isIdenticalTo(1); + $this->assertCount(1, $softs); //20.0.000 $versions = $version->find(['name' => '20.0.000']); - $this->integer(count($versions))->isIdenticalTo(1); + $this->assertCount(1, $versions); $version_data = array_pop($versions); - $this->boolean($item_version->getFromDBByCrit([ + $this->assertTrue($item_version->getFromDBByCrit([ "itemtype" => "Computer", "items_id" => $computers_id, "softwareversions_id" => $version_data['id'] - ]))->isTrue(); + ])); } public function testSameSoftManufacturer2() @@ -1220,42 +1247,42 @@ public function testSameSoftManufacturer2() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $this->doInventory($xml_source, true); //we have 1 software & versions for ÀVEVA Application Server 2020 $softs = $soft->find(['name' => 'ÀVEVA Application Server 2020']); - $this->integer(count($softs))->isIdenticalTo(1); + $this->assertCount(1, $softs); //20.0.000 $versions = $version->find(['name' => '20.0.000']); - $this->integer(count($versions))->isIdenticalTo(1); + $this->assertCount(1, $versions); $version_data = array_pop($versions); - $this->boolean($item_version->getFromDBByCrit([ + $this->assertTrue($item_version->getFromDBByCrit([ "itemtype" => "Computer", "items_id" => $computers_id, "softwareversions_id" => $version_data['id'] - ]))->isTrue(); + ])); //same inventory again $this->doInventory($xml_source, true); //we have 1 software & versions for ÀVEVA Application Server 2020 $softs = $soft->find(['name' => 'ÀVEVA Application Server 2020']); - $this->integer(count($softs))->isIdenticalTo(1); + $this->assertCount(1, $softs); //20.0.000 $versions = $version->find(['name' => '20.0.000']); - $this->integer(count($versions))->isIdenticalTo(1); + $this->assertCount(1, $versions); $version_data = array_pop($versions); - $this->boolean($item_version->getFromDBByCrit([ + $this->assertTrue($item_version->getFromDBByCrit([ "itemtype" => "Computer", "items_id" => $computers_id, "softwareversions_id" => $version_data['id'] - ]))->isTrue(); + ])); } public function testManufacturerDifferentCase() @@ -1297,53 +1324,53 @@ public function testManufacturerDifferentCase() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $this->doInventory($xml_source, true); //check software has been created - $this->boolean( + $this->assertTrue( $soft->getFromDBByCrit(['name' => 'Realtek Card Reader']) - )->isTrue(); + ); $softwares_id = $soft->fields['id']; //check version has been created - $this->boolean( + $this->assertTrue( $version->getFromDBByCrit(['name' => '10.0.17134.31242']) - )->isTrue(); - $this->integer($version->fields['softwares_id'])->isIdenticalTo($softwares_id); + ); + $this->assertSame($softwares_id, $version->fields['softwares_id']); $versions_id = $version->fields['id']; //check computer-softwareverison relation has been created - $this->boolean($item_version->getFromDBByCrit([ + $this->assertTrue($item_version->getFromDBByCrit([ "itemtype" => "Computer", "items_id" => $computers_id, "softwareversions_id" => $versions_id - ]))->isTrue(); + ])); $item_versions_id = $item_version->fields['id']; //import again $this->doInventory($xml_source, true); //check software is the same - $this->boolean( + $this->assertTrue( $soft->getFromDBByCrit(['name' => 'Realtek Card Reader']) - )->isTrue(); - $this->integer($softwares_id)->isIdenticalTo($soft->fields['id']); + ); + $this->assertSame($soft->fields['id'], $softwares_id); //check version is the same - $this->boolean( + $this->assertTrue( $version->getFromDBByCrit(['name' => '10.0.17134.31242']) - )->isTrue(); - $this->integer($versions_id)->isIdenticalTo($version->fields['id']); + ); + $this->assertSame($version->fields['id'], $versions_id); //check computer-softwareverison relation is the same - $this->boolean($item_version->getFromDBByCrit([ + $this->assertTrue($item_version->getFromDBByCrit([ "itemtype" => "Computer", "items_id" => $computers_id, "softwareversions_id" => $versions_id - ]))->isTrue(); - $this->integer($item_versions_id)->isIdenticalTo($item_version->fields['id']); + ])); + $this->assertSame($item_version->fields['id'], $item_versions_id); } public function testSoftDifferentCase() @@ -1383,53 +1410,53 @@ public function testSoftDifferentCase() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $this->doInventory($xml_source, true); //check software has been created - $this->boolean( + $this->assertTrue( $soft->getFromDBByCrit(['name' => 'texlive-ha-prosper']) - )->isTrue(); + ); $softwares_id = $soft->fields['id']; //check version has been created - $this->boolean( + $this->assertTrue( $version->getFromDBByCrit(['name' => '4.21']) - )->isTrue(); - $this->integer($version->fields['softwares_id'])->isIdenticalTo($softwares_id); + ); + $this->assertSame($softwares_id, $version->fields['softwares_id']); $versions_id = $version->fields['id']; //check computer-softwareverison relation has been created - $this->boolean($item_version->getFromDBByCrit([ + $this->assertTrue($item_version->getFromDBByCrit([ "itemtype" => "Computer", "items_id" => $computers_id, "softwareversions_id" => $versions_id - ]))->isTrue(); + ])); $item_versions_id = $item_version->fields['id']; //import again $this->doInventory($xml_source, true); //check software is the same - $this->boolean( + $this->assertTrue( $soft->getFromDBByCrit(['name' => 'texlive-ha-prosper']) - )->isTrue(); - $this->integer($softwares_id)->isIdenticalTo($soft->fields['id']); + ); + $this->assertSame($soft->fields['id'], $softwares_id); //check version is the same - $this->boolean( + $this->assertTrue( $version->getFromDBByCrit(['name' => '4.21']) - )->isTrue(); - $this->integer($versions_id)->isIdenticalTo($version->fields['id']); + ); + $this->assertSame($version->fields['id'], $versions_id); //check computer-softwareverison relation is the same - $this->boolean($item_version->getFromDBByCrit([ + $this->assertTrue($item_version->getFromDBByCrit([ "itemtype" => "Computer", "items_id" => $computers_id, "softwareversions_id" => $versions_id - ]))->isTrue(); - $this->integer($item_versions_id)->isIdenticalTo($item_version->fields['id']); + ])); + $this->assertSame($item_version->fields['id'], $item_versions_id); } public function testManufacturerSpecialCharacters() @@ -1471,53 +1498,53 @@ public function testManufacturerSpecialCharacters() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $this->doInventory($xml_source, true); //check software has been created - $this->boolean( + $this->assertTrue( $soft->getFromDBByCrit(['name' => 'Any software']) - )->isTrue(); + ); $softwares_id = $soft->fields['id']; //check version has been created - $this->boolean( + $this->assertTrue( $version->getFromDBByCrit(['name' => '1.0.0']) - )->isTrue(); - $this->integer($version->fields['softwares_id'])->isIdenticalTo($softwares_id); + ); + $this->assertSame($softwares_id, $version->fields['softwares_id']); $versions_id = $version->fields['id']; //check computer-softwareverison relation has been created - $this->boolean($item_version->getFromDBByCrit([ + $this->assertTrue($item_version->getFromDBByCrit([ "itemtype" => "Computer", "items_id" => $computers_id, "softwareversions_id" => $versions_id - ]))->isTrue(); + ])); $item_versions_id = $item_version->fields['id']; //import again $this->doInventory($xml_source, true); //check software is the same - $this->boolean( + $this->assertTrue( $soft->getFromDBByCrit(['name' => 'Any software']) - )->isTrue(); - $this->integer($softwares_id)->isIdenticalTo($soft->fields['id']); + ); + $this->assertSame($soft->fields['id'], $softwares_id); //check version is the same - $this->boolean( + $this->assertTrue( $version->getFromDBByCrit(['name' => '1.0.0']) - )->isTrue(); - $this->integer($versions_id)->isIdenticalTo($version->fields['id']); + ); + $this->assertSame($version->fields['id'], $versions_id); //check computer-softwareverison relation is the same - $this->boolean($item_version->getFromDBByCrit([ + $this->assertTrue($item_version->getFromDBByCrit([ "itemtype" => "Computer", "items_id" => $computers_id, "softwareversions_id" => $versions_id - ]))->isTrue(); - $this->integer($item_versions_id)->isIdenticalTo($item_version->fields['id']); + ])); + $this->assertSame($item_version->fields['id'], $item_versions_id); } public function testSubCategoryDictionnary() @@ -1540,22 +1567,27 @@ public function testSubCategoryDictionnary() 'is_recursive' => 0, 'ranking' => 1, ]); - $this->integer((int) $rules_id)->isGreaterThan(0); - - $this->integer((int) $rulecriteria->add([ - 'rules_id' => $rules_id, - 'criteria' => 'name', - 'condition' => \Rule::PATTERN_IS, - 'pattern' => 'firefox' - ]))->isGreaterThan(0); - - $this->integer((int) $ruleaction->add([ - 'rules_id' => $rules_id, - 'action_type' => 'assign', - 'field' => 'softwarecategories_id', - 'value' => $categories_id, - ]))->isGreaterThan(0); - + $this->assertGreaterThan(0, (int) $rules_id); + + $this->assertGreaterThan( + 0, + (int) $rulecriteria->add([ + 'rules_id' => $rules_id, + 'criteria' => 'name', + 'condition' => \Rule::PATTERN_IS, + 'pattern' => 'firefox' + ]) + ); + + $this->assertGreaterThan( + 0, + (int) $ruleaction->add([ + 'rules_id' => $rules_id, + 'action_type' => 'assign', + 'field' => 'softwarecategories_id', + 'value' => $categories_id, + ]) + ); $xml_source = " @@ -1591,13 +1623,13 @@ public function testSubCategoryDictionnary() $computer = new \Computer(); $found_computers = $computer->find(['name' => "pc_test_entity"]); - $this->integer(count($found_computers))->isIdenticalTo(1); + $this->assertCount(1, $found_computers); $soft = new \Software(); $softs = $soft->find(['name' => "firefox"]); - $this->integer(count($softs))->isIdenticalTo(1); + $this->assertCount(1, $softs); $first_soft = array_pop($softs); - $this->integer($first_soft['softwarecategories_id'])->isIdenticalTo($categories_id); + $this->assertSame($categories_id, $first_soft['softwarecategories_id']); } } diff --git a/tests/functional/Glpi/Inventory/Assets/SoundCard.php b/phpunit/functional/Glpi/Inventory/Assets/SoundCard.php similarity index 83% rename from tests/functional/Glpi/Inventory/Assets/SoundCard.php rename to phpunit/functional/Glpi/Inventory/Assets/SoundCard.php index 4496a878f3c..fd070601b98 100644 --- a/tests/functional/Glpi/Inventory/Assets/SoundCard.php +++ b/phpunit/functional/Glpi/Inventory/Assets/SoundCard.php @@ -41,7 +41,7 @@ class SoundCard extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -76,7 +76,7 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\SoundCard($computer, $json->content->sounds); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -85,8 +85,10 @@ public function testHandle() //first, check there are no soundcard linked to this computer $ids = new \Item_DeviceSoundCard(); - $this->boolean($ids->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A soundcard is already linked to computer!'); + $this->assertFalse( + $ids->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A soundcard is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -99,13 +101,15 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\SoundCard($computer, $json->content->sounds); $asset->setExtraData((array)$json->content); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($ids->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Soundcard has not been linked to computer :('); + $this->assertTrue( + $ids->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Soundcard has not been linked to computer :(' + ); } public function testInventoryUpdate() @@ -146,65 +150,65 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $manufacturer = new \Manufacturer(); $manufacturers_id = $manufacturer->add([ 'name' => 'Intel Corporation' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $sound_1_id = $device_sound->add([ 'designation' => 'Audio device', 'manufacturers_id' => $manufacturers_id, 'entities_id' => 0 ]); - $this->integer($sound_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $sound_1_id); $item_sound_1_id = $item_sound->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicesoundcards_id' => $sound_1_id ]); - $this->integer($item_sound_1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_sound_1_id); $manufacturers_id = $manufacturer->add([ 'name' => 'Realtek' ]); - $this->integer($manufacturers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $manufacturers_id); $sound_2_id = $device_sound->add([ 'designation' => 'Realtek High Definition Audio', 'manufacturers_id' => $manufacturers_id, 'entities_id' => 0 ]); - $this->integer($sound_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $sound_2_id); $item_sound_2_id = $item_sound->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicesoundcards_id' => $sound_2_id ]); - $this->integer($item_sound_2_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_sound_2_id); $sound_3_id = $device_sound->add([ 'designation' => 'My Sound Card', 'manufacturers_id' => $manufacturers_id, 'entities_id' => 0 ]); - $this->integer($sound_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $sound_3_id); $item_sound_3_id = $item_sound->add([ 'items_id' => $computers_id, 'itemtype' => 'Computer', 'devicesoundcards_id' => $sound_3_id ]); - $this->integer($item_sound_3_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $item_sound_3_id); $sounds = $item_sound->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($sounds))->isIdenticalTo(3); + $this->assertCount(3, $sounds); foreach ($sounds as $sound) { - $this->variable($sound['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $sound['is_dynamic']); } //computer inventory knows only "Intel" and "Realtek" sound cards @@ -212,19 +216,19 @@ public function testInventoryUpdate() //we still have 3 sound cards $sounds = $device_sound->find(); - $this->integer(count($sounds))->isIdenticalTo(3); + $this->assertCount(3, $sounds); //we still have 3 sound cards items linked to the computer $sounds = $item_sound->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($sounds))->isIdenticalTo(3); + $this->assertCount(3, $sounds); //sound cards present in the inventory source are now dynamic $sounds = $item_sound->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($sounds))->isIdenticalTo(2); + $this->assertCount(2, $sounds); //sound card not present in the inventory is still not dynamic $sounds = $item_sound->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($sounds))->isIdenticalTo(1); + $this->assertCount(1, $sounds); //Redo inventory, but with removed "Realtek" sound card $xml_source = " @@ -251,18 +255,18 @@ public function testInventoryUpdate() //we still have 3 sound cards $sounds = $device_sound->find(); - $this->integer(count($sounds))->isIdenticalTo(3); + $this->assertCount(3, $sounds); //we now have 2 sound cards linked to computer only $sounds = $item_sound->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($sounds))->isIdenticalTo(2); + $this->assertCount(2, $sounds); //sound card present in the inventory source is still dynamic $sounds = $item_sound->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($sounds))->isIdenticalTo(1); + $this->assertCount(1, $sounds); //sound card not present in the inventory is still not dynamic $sounds = $item_sound->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($sounds))->isIdenticalTo(1); + $this->assertCount(1, $sounds); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Unmanaged.php b/phpunit/functional/Glpi/Inventory/Assets/Unmanaged.php similarity index 79% rename from tests/functional/Glpi/Inventory/Assets/Unmanaged.php rename to phpunit/functional/Glpi/Inventory/Assets/Unmanaged.php index 5894652435d..cac842011b1 100644 --- a/tests/functional/Glpi/Inventory/Assets/Unmanaged.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Unmanaged.php @@ -43,7 +43,7 @@ class Unmanaged extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -98,7 +98,7 @@ public function testPrepare($xml, $expected) $converter = new \Glpi\Inventory\Converter(); $data = $converter->convert($xml); $json = json_decode($data); - $this->object($json)->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $json); } @@ -143,7 +143,7 @@ public function testInventory() 'items_id' => 0 //Core ]); - $this->integer($agent_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $agent_id); //create rule $this->login(); $entity = new \Entity(); @@ -154,7 +154,7 @@ public function testInventory() 'level' => 2, 'tag' => 'entA' ]); - $this->integer($entities_id_a)->isGreaterThan(0); + $this->assertGreaterThan(0, $entities_id_a); $entities_id_b = $entity->add([ 'name' => 'Entity B', @@ -163,7 +163,7 @@ public function testInventory() 'level' => 2, 'tag' => 'sub' ]); - $this->integer($entities_id_b)->isGreaterThan(0); + $this->assertGreaterThan(0, $entities_id_b); // Add a rule for get entity tag (1) $rule = new \Rule(); @@ -175,7 +175,7 @@ public function testInventory() 'ranking' => 1 ]; $rule1_id = $rule->add($input); - $this->integer($rule1_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule1_id); // Add criteria $rulecriteria = new \RuleCriteria(); @@ -185,7 +185,7 @@ public function testInventory() 'pattern' => "/(.*)/", 'condition' => \RuleImportEntity::REGEX_MATCH ]; - $this->integer($rulecriteria->add($input))->isGreaterThan(0); + $this->assertGreaterThan(0, $rulecriteria->add($input)); $input = [ 'rules_id' => $rule1_id, @@ -193,7 +193,7 @@ public function testInventory() 'pattern' => "Unmanaged", 'condition' => \RuleImportEntity::PATTERN_IS ]; - $this->integer($rulecriteria->add($input))->isGreaterThan(0); + $this->assertGreaterThan(0, $rulecriteria->add($input)); // Add action $ruleaction = new \RuleAction(); @@ -203,81 +203,81 @@ public function testInventory() 'field' => '_affect_entity_by_tag', 'value' => '#0' ]; - $this->integer($ruleaction->add($input))->isGreaterThan(0); + $this->assertGreaterThan(0, $ruleaction->add($input)); $this->doInventory($xml, true); //no Agent from discovery $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); //check for one Unmanaged $unmanaged = new \Unmanaged(); - $this->boolean($unmanaged->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF']))->isTrue(); + $this->assertTrue($unmanaged->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF'])); //check last_inventory_update - $this->variable($unmanaged->fields['last_inventory_update'])->isEqualTo($_SESSION['glpi_currenttime']); + $this->assertEquals($_SESSION['glpi_currenttime'], $unmanaged->fields['last_inventory_update']); //check entity - $this->variable($unmanaged->fields['entities_id'])->isEqualTo($entities_id_b); + $this->assertEquals($entities_id_b, $unmanaged->fields['entities_id']); //check for one NetworkPort $np = new \NetworkPort(); $nps = $np->find(["itemtype" => \Unmanaged::class, "items_id" => $unmanaged->fields['id'], "mac" => "4c:cc:6a:02:13:a9"]); - $this->integer(count($nps))->isIdenticalTo(1); + $this->assertCount(1, $nps); //check for one IPAdress $ip = new \IPAddress(); $ips = $ip->find(["mainitemtype" => \Unmanaged::class, "mainitems_id" => $unmanaged->fields['id'], "name" => "192.168.1.20"]); - $this->integer(count($ips))->isIdenticalTo(1); + $this->assertCount(1, $ips); $rm = new \RuleMatchedLog(); //check for one RuleMatchLog $rms = $rm->find(["itemtype" => \Unmanaged::class, "items_id" => $unmanaged->fields['id']]); - $this->integer(count($rms))->isIdenticalTo(1); + $this->assertCount(1, $rms); //update field to create locked field //update computer to add lock on serial - $this->boolean($unmanaged->update([ + $this->assertTrue($unmanaged->update([ 'id' => $unmanaged->fields['id'], 'users_id' => getItemByTypeName('User', 'glpi', true) - ]))->isTrue(); + ])); //get lockedfield field $lock = new \Lockedfield(); $locks = $lock->find(["itemtype" => \Unmanaged::class, "items_id" => $unmanaged->fields['id'], "field" => "users_id"]); - $this->integer(count($locks))->isIdenticalTo(1); + $this->assertCount(1, $locks); //redo inventory $this->doInventory($xml, true); //check for always one Unmanaged - $this->boolean($unmanaged->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF']))->isTrue(); + $this->assertTrue($unmanaged->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF'])); //check last_inventory_update - $this->variable($unmanaged->fields['last_inventory_update'])->isEqualTo($_SESSION['glpi_currenttime']); + $this->assertEquals($_SESSION['glpi_currenttime'], $unmanaged->fields['last_inventory_update']); //check entity - $this->variable($unmanaged->fields['entities_id'])->isEqualTo($entities_id_b); + $this->assertEquals($entities_id_b, $unmanaged->fields['entities_id']); //check for lock $locks = $lock->find(["itemtype" => \Unmanaged::class, "items_id" => $unmanaged->fields['id'], "field" => "users_id"]); - $this->integer(count($locks))->isIdenticalTo(1); + $this->assertCount(1, $locks); //check for always one NetworkPort $nps = $np->find(["itemtype" => \Unmanaged::class, "items_id" => $unmanaged->fields['id'], "mac" => "4c:cc:6a:02:13:a9"]); - $this->integer(count($nps))->isIdenticalTo(1); + $this->assertCount(1, $nps); //check for always one IPAddress $ips = $ip->find(["mainitemtype" => \Unmanaged::class, "mainitems_id" => $unmanaged->fields['id'], "name" => "192.168.1.20"]); - $this->integer(count($ips))->isIdenticalTo(1); + $this->assertCount(1, $ips); //check for 2 RuleMatchLog $rms = $rm->find(["itemtype" => \Unmanaged::class, "items_id" => $unmanaged->fields['id']]); - $this->integer(count($rms))->isIdenticalTo(2); + $this->assertCount(2, $rms); $xml = " @@ -302,91 +302,91 @@ public function testInventory() $this->doInventory($xml, true); //check for always one Unmanaged - $this->boolean($unmanaged->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF']))->isTrue(); + $this->assertTrue($unmanaged->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF'])); //check last_inventory_update - $this->variable($unmanaged->fields['last_inventory_update'])->isEqualTo($_SESSION['glpi_currenttime']); + $this->assertEquals($_SESSION['glpi_currenttime'], $unmanaged->fields['last_inventory_update']); //check entity - $this->variable($unmanaged->fields['entities_id'])->isEqualTo($entities_id_b); + $this->assertEquals($entities_id_b, $unmanaged->fields['entities_id']); //check for lock $locks = $lock->find(["itemtype" => \Unmanaged::class, "items_id" => $unmanaged->fields['id'], "field" => "users_id"]); - $this->integer(count($locks))->isIdenticalTo(1); + $this->assertCount(1, $locks); //check for always one NetworkPort $nps = $np->find(["itemtype" => \Unmanaged::class, "items_id" => $unmanaged->fields['id'], "mac" => "4c:cc:6a:02:13:a9"]); - $this->integer(count($nps))->isIdenticalTo(1); + $this->assertCount(1, $nps); //check for always one IPAddress but .22 $ips = $ip->find(["mainitemtype" => \Unmanaged::class, "mainitems_id" => $unmanaged->fields['id'], "name" => "192.168.1.22"]); - $this->integer(count($ips))->isIdenticalTo(1); + $this->assertCount(1, $ips); //check for 3 RuleMatchLog $rms = $rm->find(["itemtype" => \Unmanaged::class, "items_id" => $unmanaged->fields['id']]); - $this->integer(count($rms))->isIdenticalTo(3); + $this->assertCount(3, $rms); //convert as Computer $unmanaged->convert($unmanaged->fields['id'], "Computer"); //unamage device no longer exist - $this->boolean($unmanaged->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF']))->isFalse(); + $this->assertFalse($unmanaged->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF'])); //check computer exist now $computer = new \Computer(); - $this->boolean($computer->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF']))->isTrue(); + $this->assertTrue($computer->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF'])); //check last_inventory_update - $this->variable($computer->fields['last_inventory_update'])->isEqualTo($_SESSION['glpi_currenttime']); + $this->assertEquals($_SESSION['glpi_currenttime'], $computer->fields['last_inventory_update']); //check entity - $this->variable($computer->fields['entities_id'])->isEqualTo($entities_id_b); + $this->assertEquals($entities_id_b, $computer->fields['entities_id']); //check for lock move to computer $locks = $lock->find(["itemtype" => \Computer::class, "items_id" => $computer->fields['id'], "field" => "users_id"]); - $this->integer(count($locks))->isIdenticalTo(1); + $this->assertCount(1, $locks); //check for lock move to computer $locks = $lock->find(["itemtype" => \Unmanaged::class, "items_id" => $computer->fields['id'], "field" => "users_id"]); - $this->integer(count($locks))->isIdenticalTo(0); + $this->assertCount(0, $locks); //check for always one NetworkPort $nps = $np->find(["itemtype" => \Computer::class, "items_id" => $computer->fields['id'], "mac" => "4c:cc:6a:02:13:a9"]); - $this->integer(count($nps))->isIdenticalTo(1); + $this->assertCount(1, $nps); //check for always one IPAddress but .22 $ips = $ip->find(["mainitemtype" => \Computer::class, "mainitems_id" => $computer->fields['id'], "name" => "192.168.1.22"]); - $this->integer(count($ips))->isIdenticalTo(1); + $this->assertCount(1, $ips); //check for 3 RuleMatchLog $rms = $rm->find(["itemtype" => \Computer::class, "items_id" => $computer->fields['id']]); - $this->integer(count($rms))->isIdenticalTo(3); + $this->assertCount(3, $rms); //redo inventory $this->doInventory($xml, true); //check for one computer $computer = new \Computer(); - $this->boolean($computer->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF']))->isTrue(); + $this->assertTrue($computer->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF'])); //check last_inventory_update - $this->variable($computer->fields['last_inventory_update'])->isEqualTo($_SESSION['glpi_currenttime']); + $this->assertEquals($_SESSION['glpi_currenttime'], $computer->fields['last_inventory_update']); //check entity - $this->variable($computer->fields['entities_id'])->isEqualTo($entities_id_b); + $this->assertEquals($entities_id_b, $computer->fields['entities_id']); //check for always one NetworkPort $nps = $np->find(["itemtype" => \Computer::class, "items_id" => $computer->fields['id'], "mac" => "4c:cc:6a:02:13:a9"]); - $this->integer(count($nps))->isIdenticalTo(1); + $this->assertCount(1, $nps); //check for always one IPAddress but .22 $ips = $ip->find(["mainitemtype" => \Computer::class, "mainitems_id" => $computer->fields['id'], "name" => "192.168.1.22"]); - $this->integer(count($ips))->isIdenticalTo(1); + $this->assertCount(1, $ips); //check for 4 RuleMatchLog $rms = $rm->find(["itemtype" => \Computer::class, "items_id" => $computer->fields['id']]); - $this->integer(count($rms))->isIdenticalTo(4); + $this->assertCount(4, $rms); //redo inventory with users_id $xml = " @@ -416,13 +416,13 @@ public function testInventory() //check for one computer $computer = new \Computer(); - $this->boolean($computer->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF']))->isTrue(); + $this->assertTrue($computer->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF'])); //check users_id is always glpi - $this->variable($computer->fields['users_id'])->isEqualTo(getItemByTypeName('User', 'glpi', true)); + $this->assertEquals(getItemByTypeName('User', 'glpi', true), $computer->fields['users_id']); //release lock - $this->boolean($lock->deleteByCriteria(["itemtype" => \Computer::class, "items_id" => $computer->fields['id'], "field" => "users_id"]))->isTrue(); + $this->assertTrue($lock->deleteByCriteria(["itemtype" => \Computer::class, "items_id" => $computer->fields['id'], "field" => "users_id"])); //redo inventory with another user $xml = " @@ -452,10 +452,10 @@ public function testInventory() //check for one computer $computer = new \Computer(); - $this->boolean($computer->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF']))->isTrue(); + $this->assertTrue($computer->getFromDbByCrit(['name' => 'DESKTOP-A3J16LF'])); //check users_id is changed to tech - $this->variable($computer->fields['users_id'])->isEqualTo(getItemByTypeName('User', 'tech', true)); + $this->assertEquals(getItemByTypeName('User', 'tech', true), $computer->fields['users_id']); } @@ -490,18 +490,18 @@ public function testAgentNotDeleted() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps.teclib.infra-2018-10-03-08-42-36') - ->string['itemtype']->isIdenticalTo('Computer'); + $this->assertIsArray($agent); + $this->assertSame('glpixps.teclib.infra-2018-10-03-08-42-36', $agent['deviceid']); + $this->assertSame('Computer', $agent['itemtype']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //do network discovery with another agent global $DB; @@ -529,15 +529,15 @@ public function testAgentNotDeleted() //check Unmanaged not exist (since an asset with the same MAC exists) $unmanaged = new \Unmanaged(); - $this->boolean($unmanaged->getFromDbByCrit(['name' => 'glpixps']))->isFalse(); + $this->assertFalse($unmanaged->getFromDbByCrit(['name' => 'glpixps'])); //reload agent $agent_reload = new \Agent(); - $this->boolean($agent_reload->getFromDB($agent['id']))->isTrue(); + $this->assertTrue($agent_reload->getFromDB($agent['id'])); //check is always linked to computer - $this->string($agent_reload->fields['itemtype'])->isIdenticalTo("Computer"); - $this->integer($agent_reload->fields['items_id'])->isIdenticalTo($computers_id); + $this->assertSame("Computer", $agent_reload->fields['itemtype']); + $this->assertSame($computers_id, $agent_reload->fields['items_id']); } public function testState() @@ -551,7 +551,7 @@ public function testState() $inv_states_id = $state->add([ 'name' => 'In use' ]); - $this->integer($inv_states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $inv_states_id); \Config::setConfigurationValues( 'inventory', @@ -670,25 +670,25 @@ public function testState() //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('teclib-asus-desktop-2022-09-20-16-43-09') - ->string['name']->isIdenticalTo('teclib-asus-desktop-2022-09-20-16-43-09') - ->string['version']->isIdenticalTo('1.4-1') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['tag']->isIdenticalTo('sub') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']) - ->integer['items_id']->isGreaterThan(0); + $this->assertIsArray($agent); + $this->assertSame('teclib-asus-desktop-2022-09-20-16-43-09', $agent['deviceid']); + $this->assertSame('teclib-asus-desktop-2022-09-20-16-43-09', $agent['name']); + $this->assertSame('1.4-1', $agent['version']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame('sub', $agent['tag']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); + $this->assertGreaterThan(0, $agent['items_id']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check states has been set - $this->integer($computer->fields['states_id'])->isIdenticalTo($inv_states_id); + $this->assertSame($inv_states_id, $computer->fields['states_id']); //run discovery $xml_source = ' @@ -715,12 +715,12 @@ public function testState() //no Unmanaged create $unmanaged = new \Unmanaged(); $found = $unmanaged->find(); - $this->array($found)->hasSize(0); + $this->assertCount(0, $found); //reload computer - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check that state has not change - $this->integer($computer->fields['states_id'])->isIdenticalTo($inv_states_id); + $this->assertSame($inv_states_id, $computer->fields['states_id']); } } diff --git a/tests/functional/Glpi/Inventory/Assets/VirtualMachine.php b/phpunit/functional/Glpi/Inventory/Assets/VirtualMachine.php similarity index 87% rename from tests/functional/Glpi/Inventory/Assets/VirtualMachine.php rename to phpunit/functional/Glpi/Inventory/Assets/VirtualMachine.php index 568ffd11f75..effba7c1b16 100644 --- a/tests/functional/Glpi/Inventory/Assets/VirtualMachine.php +++ b/phpunit/functional/Glpi/Inventory/Assets/VirtualMachine.php @@ -41,7 +41,7 @@ class VirtualMachine extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -118,11 +118,11 @@ public function testPrepare($xml, $expected) $asset = new \Glpi\Inventory\Asset\VirtualMachine($computer, $json->content->virtualmachines); $asset->setExtraData((array)$json->content); $conf = new \Glpi\Inventory\Conf(); - $this->boolean( + $this->assertTrue( $asset->checkConf($conf) - )->isTrue(); + ); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -131,8 +131,10 @@ public function testHandle() //first, check there are no vms linked to this computer $cvm = new \ComputerVirtualMachine(); - $this->boolean($cvm->getFromDbByCrit(['computers_id' => $computer->fields['id']])) - ->isFalse('A virtual machine is already linked to computer!'); + $this->assertFalse( + $cvm->getFromDbByCrit(['computers_id' => $computer->fields['id']]), + 'A virtual machine is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -145,26 +147,28 @@ public function testHandle() $asset = new \Glpi\Inventory\Asset\VirtualMachine($computer, $json->content->virtualmachines); $asset->setExtraData((array)$json->content); $conf = new \Glpi\Inventory\Conf(); - $this->boolean( + $this->assertTrue( $asset->checkConf($conf) - )->isTrue(); + ); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); $agent = new \Agent(); $agent->getEmpty(); $asset->setAgent($agent); $conf = new \Glpi\Inventory\Conf(); - $this->boolean( + $this->assertTrue( $asset->checkConf($conf) - )->isTrue(); + ); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($cvm->getFromDbByCrit(['computers_id' => $computer->fields['id']])) - ->isTrue('Virtual machine has not been linked to computer :('); + $this->assertTrue( + $cvm->getFromDbByCrit(['computers_id' => $computer->fields['id']]), + 'Virtual machine has not been linked to computer :(' + ); } public function testImportVirtualMachine() @@ -238,32 +242,32 @@ public function testImportVirtualMachine() //change config to import vms as computers $this->login(); $conf = new \Glpi\Inventory\Conf(); - $this->boolean($conf->saveConf(['vm_as_computer' => 1]))->isTrue(); + $this->assertTrue($conf->saveConf(['vm_as_computer' => 1])); $this->logout(); //computer inventory knows bios $inventory = $this->doInventory($xml_source, true); $esx_id_first = $inventory->getItem()->fields['id']; - $this->integer($esx_id_first)->isGreaterThan(0); + $this->assertGreaterThan(0, $esx_id_first); //always one VM $vm = new \ComputerVirtualMachine(); - $this->array($vm->find())->hasSize(1); + $this->assertCount(1, $vm->find()); //get ComputervirtualMachine $vm_first = new \ComputerVirtualMachine(); - $this->boolean($vm_first->getFromDBByCrit([ + $this->assertTrue($vm_first->getFromDBByCrit([ 'uuid' => '420904fe-6a92-95e8-13f9-a37fc3607c14', 'computers_id' => $esx_id_first - ]))->isTrue(); + ])); //get Computer $computer_linked_first = new \Computer(); - $this->boolean($computer_linked_first->getFromDBByCrit([ + $this->assertTrue($computer_linked_first->getFromDBByCrit([ 'uuid' => '420904fe-6a92-95e8-13f9-a37fc3607c14', - ]))->isTrue(); + ])); $xml_source = " @@ -335,30 +339,30 @@ public function testImportVirtualMachine() $inventory = $this->doInventory($xml_source, true); $esx_id_second = $inventory->getItem()->fields['id']; - $this->integer($esx_id_second)->isGreaterThan(0); + $this->assertGreaterThan(0, $esx_id_second); - $this->integer($esx_id_first)->isEqualTo($esx_id_second); + $this->assertSame($esx_id_second, $esx_id_first); //always one VM $vm = new \ComputerVirtualMachine(); - $this->array($vm->find())->hasSize(1); + $this->assertCount(1, $vm->find()); //get ComputervirtualMachine $vm_second = new \ComputerVirtualMachine(); - $this->boolean($vm_second->getFromDBByCrit([ + $this->assertTrue($vm_second->getFromDBByCrit([ 'uuid' => 'fe040942-926a-e895-13f9-a37fc3607c14', 'computers_id' => $esx_id_second - ]))->isTrue(); + ])); //get Computer $computer_linked_second = new \Computer(); - $this->boolean($computer_linked_second->getFromDBByCrit([ + $this->assertTrue($computer_linked_second->getFromDBByCrit([ 'uuid' => 'fe040942-926a-e895-13f9-a37fc3607c14', - ]))->isTrue(); + ])); //same VM and Computer - $this->integer($vm_first->fields['id'])->isEqualTo($vm_second->fields['id']); - $this->integer($computer_linked_first->fields['id'])->isEqualTo($computer_linked_second->fields['id']); + $this->assertSame($vm_second->fields['id'], $vm_first->fields['id']); + $this->assertSame($computer_linked_second->fields['id'], $computer_linked_first->fields['id']); } public function testImportVirtualMachineWithoutHistory() @@ -413,46 +417,46 @@ public function testImportVirtualMachineWithoutHistory() //change config to import vms as computers $this->login(); $conf = new \Glpi\Inventory\Conf(); - $this->boolean($conf->saveConf(['vm_as_computer' => 1]))->isTrue(); + $this->assertTrue($conf->saveConf(['vm_as_computer' => 1])); $this->logout(); //computer inventory knows bios $inventory = $this->doInventory($xml_source, true); $esx_id_first = $inventory->getItem()->fields['id']; - $this->integer($esx_id_first)->isGreaterThan(0); + $this->assertGreaterThan(0, $esx_id_first); //get two VM $vm = new \ComputerVirtualMachine(); - $this->array($vm->find())->hasSize(2); + $this->assertCount(2, $vm->find()); //get first ComputervirtualMachine -> not deleted / purged $firlst_vm = new \ComputerVirtualMachine(); - $this->boolean($firlst_vm->getFromDBByCrit([ + $this->assertTrue($firlst_vm->getFromDBByCrit([ 'uuid' => 'fe040942-926a-e895-13f9-a37fc3607c14', 'computers_id' => $esx_id_first, 'is_deleted' => false - ]))->isTrue(); + ])); //get related computer with fe040942-926a-e895-13f9-a37fc3607c14 -> not deleted / purged $first_computer_linked = new \Computer(); - $this->boolean($first_computer_linked->getFromDBByCrit([ + $this->assertTrue($first_computer_linked->getFromDBByCrit([ 'uuid' => 'fe040942-926a-e895-13f9-a37fc3607c14', 'is_deleted' => false - ]))->isTrue(); + ])); //get second ComputervirtualMachine -> not deleted / purged $second_vm = new \ComputerVirtualMachine(); - $this->boolean($second_vm->getFromDBByCrit([ + $this->assertTrue($second_vm->getFromDBByCrit([ 'uuid' => 'c37f7ce8-af95-4676-b454-0959f2c5e162', 'computers_id' => $esx_id_first, 'is_deleted' => false - ]))->isTrue(); + ])); //get computer with c37f7ce8-af95-4676-b454-0959f2c5e162 -> not deleted / purged $second_computer_linked = new \Computer(); - $this->boolean($second_computer_linked->getFromDBByCrit([ + $this->assertTrue($second_computer_linked->getFromDBByCrit([ 'uuid' => 'c37f7ce8-af95-4676-b454-0959f2c5e162', 'is_deleted' => false - ]))->isTrue(); + ])); //redi inventory without c37f7ce8-af95-4676-b454-0959f2c5e162 $xml_source = " @@ -497,34 +501,34 @@ public function testImportVirtualMachineWithoutHistory() //now one VM $vm = new \ComputerVirtualMachine(); - $this->array($vm->find())->hasSize(1); + $this->assertCount(1, $vm->find()); //get first ComputervirtualMachine -> not deleted / purged $firlst_vm = new \ComputerVirtualMachine(); - $this->boolean($firlst_vm->getFromDBByCrit([ + $this->assertTrue($firlst_vm->getFromDBByCrit([ 'uuid' => 'fe040942-926a-e895-13f9-a37fc3607c14', 'computers_id' => $esx_id_first, 'is_deleted' => false - ]))->isTrue(); + ])); //get computer with fe040942-926a-e895-13f9-a37fc3607c14 -> not deleted / purged $first_computer_linked = new \Computer(); - $this->boolean($first_computer_linked->getFromDBByCrit([ + $this->assertTrue($first_computer_linked->getFromDBByCrit([ 'uuid' => 'fe040942-926a-e895-13f9-a37fc3607c14', 'is_deleted' => false - ]))->isTrue(); + ])); //get second ComputervirtualMachine -> purged $second_vm = new \ComputerVirtualMachine(); - $this->boolean($second_vm->getFromDBByCrit([ + $this->assertFalse($second_vm->getFromDBByCrit([ 'uuid' => 'c37f7ce8-af95-4676-b454-0959f2c5e162', 'computers_id' => $esx_id_first - ]))->isFalse(); + ])); //get computer with c37f7ce8-af95-4676-b454-0959f2c5e162 -> not deleted / purged $second_computer_linked = new \Computer(); - $this->boolean($second_computer_linked->getFromDBByCrit([ + $this->assertTrue($second_computer_linked->getFromDBByCrit([ 'uuid' => 'c37f7ce8-af95-4676-b454-0959f2c5e162', 'is_deleted' => false - ]))->isTrue(); + ])); } /** @@ -603,65 +607,67 @@ public function testImportComputerFromVirtualMachine() 'condition' => 0, 'description' => '' ]); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); // Move rule to top ranking so other rules cannot interfere $collection = new \RuleImportAssetCollection(); - $this->boolean($collection->moveRule($rules_id, 0, \RuleCollection::MOVE_BEFORE))->isTrue(); + $this->assertTrue($collection->moveRule($rules_id, 0, \RuleCollection::MOVE_BEFORE)); - $this->integer( + $this->assertGreaterThan( + 0, $criteria->add([ 'rules_id' => $rules_id, 'criteria' => 'name', 'condition' => \Rule::PATTERN_CONTAIN, 'pattern' => 'REFUSED' ]) - )->isGreaterThan(0); + ); - $this->integer( + $this->assertGreaterThan( + 0, $action->add([ 'rules_id' => $rules_id, 'action_type' => 'assign', 'field' => '_inventory', 'value' => '2' //import denied ]) - )->isGreaterThan(0); + ); //change config to import vms as computers $this->login(); $conf = new \Glpi\Inventory\Conf(); - $this->boolean($conf->saveConf(['vm_as_computer' => 1]))->isTrue(); + $this->assertTrue($conf->saveConf(['vm_as_computer' => 1])); $this->logout(); //computer inventory $inventory = $this->doInventory($xml_source, true); $esx_id_first = $inventory->getItem()->fields['id']; - $this->integer($esx_id_first)->isGreaterThan(0); + $this->assertGreaterThan(0, $esx_id_first); //get three VM $vm = new \ComputerVirtualMachine(); - $this->array($vm->find())->hasSize(3); + $this->assertCount(3, $vm->find()); //get related computer with fe040942-926a-e895-13f9-a37fc3607c14 -> exist $first_computer_linked = new \Computer(); - $this->boolean($first_computer_linked->getFromDBByCrit([ + $this->assertTrue($first_computer_linked->getFromDBByCrit([ 'uuid' => 'fe040942-926a-e895-13f9-a37fc3607c14', - ]))->isTrue(); + ])); //get computer with c37f7ce8-af95-4676-b454-0959f2c5e162 -> not exist $second_computer_linked = new \Computer(); - $this->boolean($second_computer_linked->getFromDBByCrit([ + $this->assertFalse($second_computer_linked->getFromDBByCrit([ 'uuid' => 'c37f7ce8-af95-4676-b454-0959f2c5e162', - ]))->isFalse(); + ])); //get computer with 25c1bb60-5bcb-11d9-b18f-5404a6a534c4 -> exist $third_computer_linked = new \Computer(); - $this->boolean($third_computer_linked->getFromDBByCrit([ + $this->assertTrue($third_computer_linked->getFromDBByCrit([ 'uuid' => '25c1bb60-5bcb-11d9-b18f-5404a6a534c4', - ]))->isTrue(); + ])); } public function testNoMoreVirtualMachine() @@ -671,18 +677,18 @@ public function testNoMoreVirtualMachine() $inventory = $this->doInventory($source); $id_first = $inventory->getItem()->fields['id']; - $this->integer($id_first)->isGreaterThan(0); + $this->assertGreaterThan(0, $id_first); //one VM $vm = new \ComputerVirtualMachine(); - $this->array($vm->find())->hasSize(1); + $this->assertCount(1, $vm->find()); //get ComputervirtualMachine $vm = new \ComputerVirtualMachine(); - $this->boolean($vm->getFromDBByCrit([ + $this->assertTrue($vm->getFromDBByCrit([ 'uuid' => '420904fe-6a92-95e8-13f9-a37fc3607c14', 'computers_id' => $id_first - ]))->isTrue(); + ])); //make sure partial with no VM does not remove existing VMs //remove VM, but set partial @@ -692,20 +698,20 @@ public function testNoMoreVirtualMachine() $inventory = $this->doInventory($no_vm_source); $id_second = $inventory->getItem()->fields['id']; - $this->integer($id_second)->isGreaterThan(0); + $this->assertGreaterThan(0, $id_second); - $this->integer($id_first)->isEqualTo($id_second); + $this->assertSame($id_second, $id_first); //VM still present $vm = new \ComputerVirtualMachine(); - $this->array($vm->find())->hasSize(1); + $this->assertCount(1, $vm->find()); //get ComputervirtualMachine $vm = new \ComputerVirtualMachine(); - $this->boolean($vm->getFromDBByCrit([ + $this->assertTrue($vm->getFromDBByCrit([ 'uuid' => '420904fe-6a92-95e8-13f9-a37fc3607c14', 'computers_id' => $id_first - ]))->isTrue(); + ])); //remove VM, but set partial $no_vm_source = json_decode('{"content":{"hardware":{"dns":"10.100.230.2\\/10.100.230.4","memory":130625,"name":"ESX-03-DMZ","uuid":"8c8c8944-0074-5632-7452-b2c04f564712","vmsystem":"Physical","workgroup":"teclib.fr"},"versionclient":"GLPI-Agent_v1.4-1","virtualmachines":[{"comment":"Computer VM","mac":"00:50:56:90:43:42","memory":1024,"name":"SRV-DMZ-EZ","status":"running","uuid":"420904FE-6a92-95e8-13f9-a37fc3607c14","vcpu":1,"vmtype":"vmware"}]},"deviceid":"ESX-03-DMZ.insep.fr-2023-02-02-11-34-53","action":"inventory","itemtype":"Computer"}'); @@ -713,12 +719,12 @@ public function testNoMoreVirtualMachine() $inventory = $this->doInventory($no_vm_source); $id_second = $inventory->getItem()->fields['id']; - $this->integer($id_second)->isGreaterThan(0); + $this->assertGreaterThan(0, $id_second); - $this->integer($id_first)->isEqualTo($id_second); + $this->assertSame($id_second, $id_first); //no VM left $vm = new \ComputerVirtualMachine(); - $this->array($vm->find())->hasSize(0); + $this->assertCount(0, $vm->find()); } } diff --git a/tests/functional/Glpi/Inventory/Assets/Volume.php b/phpunit/functional/Glpi/Inventory/Assets/Volume.php similarity index 86% rename from tests/functional/Glpi/Inventory/Assets/Volume.php rename to phpunit/functional/Glpi/Inventory/Assets/Volume.php index 004d7bf4642..5cab2714c1f 100644 --- a/tests/functional/Glpi/Inventory/Assets/Volume.php +++ b/phpunit/functional/Glpi/Inventory/Assets/Volume.php @@ -41,7 +41,7 @@ class Volume extends AbstractInventoryAsset { - protected function assetProvider(): array + public static function assetProvider(): array { return [ [ @@ -193,10 +193,10 @@ public function testPrepare($xml, $expected) $asset->setExtraData((array)$json->content); $conf = new \Glpi\Inventory\Conf(); - $this->boolean($asset->checkConf($conf))->isTrue(); + $this->assertTrue($asset->checkConf($conf)); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected)); + $this->assertEquals(json_decode($expected), $result[0]); } public function testHandle() @@ -205,8 +205,10 @@ public function testHandle() //first, check there are no volume linked to this computer $idd = new \Item_Disk(); - $this->boolean($idd->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isFalse('A volume is already linked to computer!'); + $this->assertFalse( + $idd->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'A volume is already linked to computer!' + ); //convert data $expected = $this->assetProvider()[0]; @@ -220,16 +222,18 @@ public function testHandle() $asset->setExtraData((array)$json->content); $conf = new \Glpi\Inventory\Conf(); - $this->boolean($asset->checkConf($conf))->isTrue(); + $this->assertTrue($asset->checkConf($conf)); $result = $asset->prepare(); - $this->object($result[0])->isEqualTo(json_decode($expected['expected'])); + $this->assertEquals(json_decode($expected['expected']), $result[0]); //handle $asset->handleLinks(); $asset->handle(); - $this->boolean($idd->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer'])) - ->isTrue('Volume has not been linked to computer :('); + $this->assertTrue( + $idd->getFromDbByCrit(['items_id' => $computer->fields['id'], 'itemtype' => 'Computer']), + 'Volume has not been linked to computer :(' + ); } public function testInventoryUpdate() @@ -270,7 +274,7 @@ public function testInventoryUpdate() 'serial' => 'ggheb7ne7', 'entities_id' => 0 ]); - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $cdisk_id = $item_disk->add([ "items_id" => $computers_id, @@ -279,7 +283,7 @@ public function testInventoryUpdate() "mountpoint" => "C:", "entities_id" => 0 ]); - $this->integer($cdisk_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $cdisk_id); $ddisk_id = $item_disk->add([ "items_id" => $computers_id, @@ -288,7 +292,7 @@ public function testInventoryUpdate() "mountpoint" => "D:", "entities_id" => 0 ]); - $this->integer($ddisk_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $ddisk_id); $zdisk_id = $item_disk->add([ "items_id" => $computers_id, @@ -297,12 +301,12 @@ public function testInventoryUpdate() "mountpoint" => "Z:", "entities_id" => 0 ]); - $this->integer($zdisk_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $zdisk_id); $disks = $item_disk->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($disks))->isIdenticalTo(3); + $this->assertCount(3, $disks); foreach ($disks as $disk) { - $this->variable($disk['is_dynamic'])->isEqualTo(0); + $this->assertEquals(0, $disk['is_dynamic']); } //computer inventory knows only disks C: and Z: @@ -310,24 +314,24 @@ public function testInventoryUpdate() //we still have 3 disks linked to the computer $disks = $item_disk->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($disks))->isIdenticalTo(3); + $this->assertCount(3, $disks); //disks present in the inventory source are now dynamic $disks = $item_disk->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($disks))->isIdenticalTo(2); + $this->assertCount(2, $disks); - $this->boolean($item_disk->getFromDB($cdisk_id))->isTrue(); - $this->integer($item_disk->fields['is_dynamic'])->isIdenticalTo(1); + $this->assertTrue($item_disk->getFromDB($cdisk_id)); + $this->assertSame(1, $item_disk->fields['is_dynamic']); - $this->boolean($item_disk->getFromDB($zdisk_id))->isTrue(); - $this->integer($item_disk->fields['is_dynamic'])->isIdenticalTo(1); + $this->assertTrue($item_disk->getFromDB($zdisk_id)); + $this->assertSame(1, $item_disk->fields['is_dynamic']); //disk not present in the inventory is still not dynamic $disks = $item_disk->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($disks))->isIdenticalTo(1); + $this->assertCount(1, $disks); - $this->boolean($item_disk->getFromDB($ddisk_id))->isTrue(); - $this->integer($item_disk->fields['is_dynamic'])->isIdenticalTo(0); + $this->assertTrue($item_disk->getFromDB($ddisk_id)); + $this->assertSame(0, $item_disk->fields['is_dynamic']); //Redo inventory, but with removed disk Z: $xml_source = " @@ -358,24 +362,24 @@ public function testInventoryUpdate() //we now have 2 disks only $disks = $item_disk->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($disks))->isIdenticalTo(2); + $this->assertCount(2, $disks); //disks present in the inventory source are still dynamic $disks = $item_disk->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 1]); - $this->integer(count($disks))->isIdenticalTo(1); + $this->assertCount(1, $disks); - $this->boolean($item_disk->getFromDB($cdisk_id))->isTrue(); - $this->integer($item_disk->fields['is_dynamic'])->isIdenticalTo(1); + $this->assertTrue($item_disk->getFromDB($cdisk_id)); + $this->assertSame(1, $item_disk->fields['is_dynamic']); //Z: has been removed - $this->boolean($item_disk->getFromDB($zdisk_id))->isFalse(); + $this->assertFalse($item_disk->getFromDB($zdisk_id)); //disk not present in the inventory is still not dynamic $disks = $item_disk->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]); - $this->integer(count($disks))->isIdenticalTo(1); + $this->assertCount(1, $disks); - $this->boolean($item_disk->getFromDB($ddisk_id))->isTrue(); - $this->integer($item_disk->fields['is_dynamic'])->isIdenticalTo(0); + $this->assertTrue($item_disk->getFromDB($ddisk_id)); + $this->assertSame(0, $item_disk->fields['is_dynamic']); } public function testInventoryImportOrNot() @@ -426,26 +430,26 @@ public function testInventoryImportOrNot() //per default, configuration allows all volumes import. change that. $this->login(); $conf = new \Glpi\Inventory\Conf(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'import_volume' => 0, 'component_networkdrive' => 0, 'component_removablemedia' => 0 ]) - )->isTrue(); + ); $this->logout(); //first inventory should import no disk. $inventory = $this->doInventory($xml_source, true); $this->login(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'import_volume' => 1, 'component_networkdrive' => 1, 'component_removablemedia' => 1 ]) - )->isTrue(); + ); $this->logOut(); $computer = $inventory->getItem(); @@ -453,30 +457,30 @@ public function testInventoryImportOrNot() //no disks linked to the computer $disks = $item_disk->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($disks))->isIdenticalTo(0); + $this->assertCount(0, $disks); //set config to inventory disks, but no network nor removable $this->login(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'import_volume' => 1, 'component_networkdrive' => 0, 'component_removablemedia' => 0 ]) - )->isTrue(); + ); $this->logOut(); //first inventory should import 2 disks (C: and Z:). $inventory = $this->doInventory($xml_source, true); $this->login(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'import_volume' => 1, 'component_networkdrive' => 1, 'component_removablemedia' => 1 ]) - )->isTrue(); + ); $this->logOut(); $computer = $inventory->getItem(); @@ -484,17 +488,17 @@ public function testInventoryImportOrNot() //C: and Z: has been linked to the computer $disks = $item_disk->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($disks))->isIdenticalTo(2); + $this->assertCount(2, $disks); //set config to inventory disks, network and removable (the default) $this->login(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'import_volume' => 1, 'component_networkdrive' => 1, 'component_removablemedia' => 1 ]) - )->isTrue(); + ); $this->logout(); //inventory should import all 4 disks. @@ -505,7 +509,7 @@ public function testInventoryImportOrNot() //all disks has been linked to the computer $disks = $item_disk->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($disks))->isIdenticalTo(4); + $this->assertCount(4, $disks); $removables_id = null; foreach ($disks as $disk) { @@ -514,36 +518,36 @@ public function testInventoryImportOrNot() break; } } - $this->boolean($item_disk->getFromDB($removables_id))->isTrue(); + $this->assertTrue($item_disk->getFromDB($removables_id)); //set config to inventory disks and network, but no removable $this->login(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'import_volume' => 1, 'component_networkdrive' => 1, 'component_removablemedia' => 0 ]) - )->isTrue(); + ); $this->logout(); $this->doInventory($xml_source, true); $this->login(); - $this->boolean( + $this->assertTrue( $conf->saveConf([ 'import_volume' => 1, 'component_networkdrive' => 1, 'component_removablemedia' => 1 ]) - )->isTrue(); + ); $this->logout(); //3 disks are now been linked to the computer $disks = $item_disk->find(['itemtype' => 'Computer', 'items_id' => $computers_id]); - $this->integer(count($disks))->isIdenticalTo(3); + $this->assertCount(3, $disks); //ensure removable has been removed! - $this->boolean($item_disk->getFromDB($removables_id))->isFalse(); + $this->assertFalse($item_disk->getFromDB($removables_id)); } } diff --git a/tests/functional/Glpi/Inventory/Conf.php b/phpunit/functional/Glpi/Inventory/Conf.php similarity index 69% rename from tests/functional/Glpi/Inventory/Conf.php rename to phpunit/functional/Glpi/Inventory/Conf.php index 379a23162ec..5d63702802a 100644 --- a/tests/functional/Glpi/Inventory/Conf.php +++ b/phpunit/functional/Glpi/Inventory/Conf.php @@ -35,6 +35,8 @@ namespace tests\units\Glpi\Inventory; +use Monolog\Logger; + /** * Test class for src/Glpi/Inventory/conf.class.php */ @@ -48,14 +50,11 @@ public function testKnownInventoryExtensions() 'ocs' ]; - $this - ->if($this->newTestedInstance) - ->then - ->array($this->testedInstance->knownInventoryExtensions()) - ->isIdenticalTo($expected); + $conf = new \Glpi\Inventory\Conf(); + $this->assertSame($expected, $conf->knownInventoryExtensions()); } - protected function inventoryfilesProvider(): array + public static function inventoryfilesProvider(): array { return [ [ @@ -79,15 +78,12 @@ protected function inventoryfilesProvider(): array */ public function testIsInventoryFile(string $file, bool $expected) { - $this - ->if($this->newTestedInstance) - ->then - ->boolean($this->testedInstance->isInventoryFile($file)) - ->isIdenticalTo($expected); + $conf = new \Glpi\Inventory\Conf(); + $this->assertSame($expected, $conf->isInventoryFile($file)); } - protected function confProvider(): array + public static function confProvider(): array { $provider = []; $defaults = \Glpi\Inventory\Conf::getDefaults(); @@ -105,26 +101,15 @@ protected function confProvider(): array */ public function testGetter($key, $value) { - $this - ->if($this->newTestedInstance) - ->then - ->variable($this->testedInstance->$key) - ->isEqualTo($value); + $conf = new \Glpi\Inventory\Conf(); + $this->assertEquals($value, $conf->$key); } public function testErrorGetter() { - $this - ->if($this->newTestedInstance) - ->then - ->when( - function () { - $this->variable($this->testedInstance->doesNotExists)->isEqualTo(null); - $this->hasSessionMessages(WARNING, ['Property doesNotExists does not exists!']); - } - )->error - ->withType(E_USER_WARNING) - ->withMessage('Property doesNotExists does not exists!') - ->exists(); + $conf = new \Glpi\Inventory\Conf(); + $this->assertNull($conf->doesNotExists); + $this->hasPhpLogRecordThatContains('Property doesNotExists does not exists!', Logger::WARNING); + $this->hasSessionMessages(WARNING, ['Property doesNotExists does not exists!']); } } diff --git a/tests/functional/Glpi/Inventory/Inventory.php b/phpunit/functional/Glpi/Inventory/Inventory.php similarity index 76% rename from tests/functional/Glpi/Inventory/Inventory.php rename to phpunit/functional/Glpi/Inventory/Inventory.php index 09393650db5..a28fb223f3a 100644 --- a/tests/functional/Glpi/Inventory/Inventory.php +++ b/phpunit/functional/Glpi/Inventory/Inventory.php @@ -45,6 +45,10 @@ use RuleCriteria; use wapmorgan\UnifiedArchive\UnifiedArchive; +/** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ class Inventory extends InventoryTestCase { private function checkComputer1($computers_id) @@ -53,24 +57,24 @@ private function checkComputer1($computers_id) //get computer models, manufacturer, ... $autoupdatesystems = $DB->request(['FROM' => \AutoupdateSystem::getTable(), 'WHERE' => ['name' => 'GLPI Native Inventory']])->current(); - $this->array($autoupdatesystems); + $this->assertIsArray($autoupdatesystems); $autoupdatesystems_id = $autoupdatesystems['id']; $cmodels = $DB->request(['FROM' => \ComputerModel::getTable(), 'WHERE' => ['name' => 'XPS 13 9350']])->current(); - $this->array($cmodels); + $this->assertIsArray($cmodels); $computermodels_id = $cmodels['id']; $ctypes = $DB->request(['FROM' => \ComputerType::getTable(), 'WHERE' => ['name' => 'Laptop']])->current(); - $this->array($ctypes); + $this->assertIsArray($ctypes); $computertypes_id = $ctypes['id']; $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Dell Inc.']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); $expected = [ 'id' => $computers_id, @@ -104,7 +108,8 @@ private function checkComputer1($computers_id) 'last_inventory_update' => $computer->fields['last_inventory_update'], 'last_boot' => '2020-06-09 07:58:08', ]; - $this->array($computer->fields)->isIdenticalTo($expected); + $this->assertIsArray($computer->fields); + $this->assertSame($expected, $computer->fields); //operating system $ios = new \Item_OperatingSystem(); @@ -118,36 +123,40 @@ private function checkComputer1($computers_id) 'architecture' => 'x86_64', 'servicepack' => null, ]; - $this->array($record)->isIdenticalTo($expected); + $this->assertIsArray($record); + $this->assertSame($expected, $record); //remote management $mgmt = new \Item_RemoteManagement(); $iterator = $mgmt->getFromItem($computer); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); $remote = $iterator->current(); unset($remote['id']); - $this->array($remote)->isIdenticalTo([ - 'itemtype' => $computer->getType(), - 'items_id' => $computer->fields['id'], - 'remoteid' => '123456789', - 'type' => 'teamviewer', - 'is_dynamic' => 1, - 'is_deleted' => 0 - ]); + $this->assertSame( + [ + 'itemtype' => $computer->getType(), + 'items_id' => $computer->fields['id'], + 'remoteid' => '123456789', + 'type' => 'teamviewer', + 'is_dynamic' => 1, + 'is_deleted' => 0 + ], + $remote + ); //connections $iterator = \Computer_Item::getTypeItems($computers_id, 'Monitor'); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); $monitor_link = $iterator->current(); unset($monitor_link['date_mod']); unset($monitor_link['date_creation']); $mmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Sharp Corporation']])->current(); - $this->array($mmanuf); + $this->assertIsArray($mmanuf); $manufacturers_id = $mmanuf['id']; $mmodel = $DB->request(['FROM' => \MonitorModel::getTable(), 'WHERE' => ['name' => 'DJCP6']])->current(); - $this->array($mmodel); + $this->assertIsArray($mmodel); $models_id = $mmodel['id']; $expected = [ @@ -190,12 +199,13 @@ private function checkComputer1($computers_id) 'glpi_computers_items_is_dynamic' => 1, 'entity' => 0, ]; - $this->array($monitor_link)->isIdenticalTo($expected); + $this->assertIsArray($monitor_link); + $this->assertSame($expected, $monitor_link); $monitor = new \Monitor(); - $this->boolean($monitor->getFromDB($monitor_link['id']))->isTrue(); - $this->boolean((bool)$monitor->fields['is_dynamic'])->isTrue(); - $this->string($monitor->fields['name'])->isIdenticalTo('DJCP6'); + $this->assertTrue($monitor->getFromDB($monitor_link['id'])); + $this->assertTrue((bool)$monitor->fields['is_dynamic']); + $this->assertSame('DJCP6', $monitor->fields['name']); //check network ports $iterator = $DB->request([ @@ -205,7 +215,7 @@ private function checkComputer1($computers_id) 'itemtype' => 'Computer', ], ]); - $this->integer(count($iterator))->isIdenticalTo(5); + $this->assertCount(5, $iterator); $expecteds = [ [ @@ -266,12 +276,12 @@ private function checkComputer1($computers_id) $netport = new \NetworkPort(); foreach ($iterator as $port) { $ports_id = $port['id']; - $this->boolean($netport->getFromDB($ports_id))->isTrue(); + $this->assertTrue($netport->getFromDB($ports_id)); $instantiation = $netport->getInstantiation(); if ($port['instantiation_type'] === null) { - $this->boolean($instantiation)->isFalse(); + $this->assertFalse($instantiation); } else { - $this->object($instantiation)->isInstanceOf($port['instantiation_type']); + $this->assertInstanceOf($port['instantiation_type'], $instantiation); } unset($port['id']); @@ -304,7 +314,8 @@ private function checkComputer1($computers_id) 'lastup' => null ]; - $this->array($port)->isEqualTo($expected); + $this->assertIsArray($port); + $this->assertEquals($expected, $port); ++$i; //check for ips @@ -330,12 +341,12 @@ private function checkComputer1($computers_id) ] ]); - $this->integer(count($ip_iterator))->isIdenticalTo(count($ips[$port['name']] ?? [])); + $this->assertCount(count($ips[$port['name']] ?? []), $ip_iterator); if (isset($ips[$port['name']])) { //FIXME: missing all ipv6 :( $ip = $ip_iterator->current(); - $this->integer((int)$ip['version'])->isIdenticalTo(4); - $this->string($ip['name'])->isIdenticalTo($ips[$port['name']]['v4']); + $this->assertSame(4, (int)$ip['version']); + $this->assertSame($ips[$port['name']]['v4'], $ip['name']); } } @@ -376,8 +387,9 @@ private function checkComputer1($computers_id) ]; foreach ($expecteds as $type => $count) { - $this->integer(count($components[$type]))->isIdenticalTo( + $this->assertSame( $count, + count($components[$type]), sprintf( 'Expected %1$s %2$s, got %3$s', $count, @@ -839,12 +851,13 @@ private function checkComputer1($computers_id) } } } - $this->array($component)->isIdenticalTo($expected); + $this->assertIsArray($component); + $this->assertSame($expected, $component); } //check printer $iterator = \Computer_Item::getTypeItems($computers_id, 'Printer'); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); $printer_link = $iterator->current(); unset($printer_link['date_mod'], $printer_link['date_creation']); @@ -891,12 +904,13 @@ private function checkComputer1($computers_id) 'glpi_computers_items_is_dynamic' => 1, 'entity' => 0, ]; - $this->array($printer_link)->isIdenticalTo($expected); + $this->assertIsArray($printer_link); + $this->assertSame($expected, $printer_link); $printer = new \Printer(); - $this->boolean($printer->getFromDB($printer_link['id']))->isTrue(); - $this->boolean((bool)$printer->fields['is_dynamic'])->isTrue(); - $this->string($printer->fields['name'])->isIdenticalTo('Officejet_Pro_8600_34AF9E_'); + $this->assertTrue($printer->getFromDB($printer_link['id'])); + $this->assertTrue((bool)$printer->fields['is_dynamic']); + $this->assertSame('Officejet_Pro_8600_34AF9E_', $printer->fields['name']); return $computer; } @@ -905,7 +919,7 @@ private function checkComputer1Volumes(\Computer $computer, array $freesizes = [ { $idisks = new \Item_Disk(); $iterator = $idisks->getFromItem($computer); - $this->integer(count($iterator))->isIdenticalTo(6); + $this->assertCount(6, $iterator); $expecteds = [ [ @@ -1001,7 +1015,8 @@ private function checkComputer1Volumes(\Computer $computer, array $freesizes = [ ksort($expected); ksort($volume); - $this->array($volume)->isEqualTo($expected); + $this->assertIsArray($volume); + $this->assertEquals($expected, $volume); ++$i; } } @@ -1010,7 +1025,7 @@ private function checkComputer1Softwares(\Computer $computer, array $versions = { $isoft = new \Item_SoftwareVersion(); $iterator = $isoft->getFromItem($computer); - $this->integer(count($iterator))->isIdenticalTo(7); + $this->assertCount(7, $iterator); $expecteds = [ [ @@ -1050,11 +1065,11 @@ private function checkComputer1Softwares(\Computer $computer, array $versions = if (count($versions)) { $expected['version'] = $versions[$i]; } - $this->array([ + $this->assertEquals($expected, [ 'softname' => $soft['softname'], 'version' => $soft['version'], 'dateinstall' => $soft['dateinstall'] - ])->isEqualTo($expected); + ]); ++$i; } } @@ -1065,7 +1080,7 @@ private function checkComputer1Batteries(\Computer $computer, array $capacities $link = getItemForItemtype(\Item_DeviceBattery::class); $iterator = $DB->request($link->getTableGroupCriteria($computer)); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); $battery = []; foreach ($iterator as $row) { @@ -1096,7 +1111,8 @@ private function checkComputer1Batteries(\Computer $computer, array $capacities } } - $this->array($battery)->isIdenticalTo($expected); + $this->assertIsArray($battery); + $this->assertSame($expected, $battery); } public function testImportComputer() @@ -1109,27 +1125,27 @@ public function testImportComputer() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(7) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['version']->isIdenticalTo('FusionInventory-Agent_v2.5.2-1.fc31') - ->string['itemtype']->isIdenticalTo('Computer') - ->variable['port']->isIdenticalTo(null) - ->string['tag']->isIdenticalTo('000005'); - $this->array($metadata['provider'])->hasSize(10); + $this->assertCount(7, $metadata); + $this->assertSame('glpixps-2018-07-09-09-07-13', $metadata['deviceid']); + $this->assertSame('FusionInventory-Agent_v2.5.2-1.fc31', $metadata['version']); + $this->assertSame('Computer', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('000005', $metadata['tag']); + $this->assertCount(10, $metadata['provider']); //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['name']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['version']->isIdenticalTo('2.5.2-1.fc31') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['tag']->isIdenticalTo('000005') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']) - ->integer['items_id']->isGreaterThan(0); + $this->assertIsArray($agent); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['deviceid']); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['name']); + $this->assertSame('2.5.2-1.fc31', $agent['version']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame('000005', $agent['tag']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); + $this->assertGreaterThan(0, $agent['items_id']); //check created computer $computer = $this->checkComputer1($agent['items_id']); @@ -1140,7 +1156,7 @@ public function testImportComputer() //check matchedlogs $mlogs = new \RuleMatchedLog(); $found = $mlogs->find(); - $this->array($found)->hasSize(3); + $this->assertCount(3, $found); $criteria = [ 'FROM' => \RuleMatchedLog::getTable(), @@ -1158,23 +1174,23 @@ public function testImportComputer() $monitor_criteria = $criteria; $monitor_criteria['WHERE'] = ['itemtype' => \Monitor::getType()]; $iterator = $DB->request($monitor_criteria); - $this->integer(count($iterator))->isIdenticalTo(1); - $this->string($iterator->current()['name'])->isIdenticalTo('Monitor import (by serial)'); - $this->string($iterator->current()['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertCount(1, $iterator); + $this->assertSame('Monitor import (by serial)', $iterator->current()['name']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $iterator->current()['method']); $printer_criteria = $criteria; $printer_criteria['WHERE'] = ['itemtype' => \Printer::getType()]; $iterator = $DB->request($printer_criteria); - $this->integer(count($iterator))->isIdenticalTo(1); - $this->string($iterator->current()['name'])->isIdenticalTo('Printer import (by serial)'); - $this->string($iterator->current()['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertCount(1, $iterator); + $this->assertSame('Printer import (by serial)', $iterator->current()['name']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $iterator->current()['method']); $computer_criteria = $criteria; $computer_criteria['WHERE'] = ['itemtype' => \Computer::getType()]; $iterator = $DB->request($computer_criteria); - $this->integer(count($iterator))->isIdenticalTo(1); - $this->string($iterator->current()['name'])->isIdenticalTo('Computer import (by serial + uuid)'); - $this->string($iterator->current()['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertCount(1, $iterator); + $this->assertSame('Computer import (by serial + uuid)', $iterator->current()['name']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $iterator->current()['method']); } public function testUpdateComputer() @@ -1187,31 +1203,31 @@ public function testUpdateComputer() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(7) - ->string['deviceid']->isIdenticalTo('LF014-2017-02-20-12-19-56') - ->string['version']->isIdenticalTo('FusionInventory-Agent_v2.3.19') - ->string['itemtype']->isIdenticalTo('Computer') - ->variable['port']->isIdenticalTo(null) - ->string['tag']->isIdenticalTo('000005'); - $this->array($metadata['provider'])->hasSize(9); + $this->assertCount(7, $metadata); + $this->assertSame('LF014-2017-02-20-12-19-56', $metadata['deviceid']); + $this->assertSame('FusionInventory-Agent_v2.3.19', $metadata['version']); + $this->assertSame('Computer', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('000005', $metadata['tag']); + $this->assertCount(9, $metadata['provider']); //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('LF014-2017-02-20-12-19-56') - ->string['name']->isIdenticalTo('LF014-2017-02-20-12-19-56') - ->string['version']->isIdenticalTo('2.3.19') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['tag']->isIdenticalTo('000005') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']); + $this->assertIsArray($agent); + $this->assertSame('LF014-2017-02-20-12-19-56', $agent['deviceid']); + $this->assertSame('LF014-2017-02-20-12-19-56', $agent['name']); + $this->assertSame('2.3.19', $agent['version']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame('000005', $agent['tag']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); //check matchedlogs $mlogs = new \RuleMatchedLog(); $mrules_found = $mlogs->find(); - $this->array($mrules_found)->hasSize(2); + $this->assertCount(2, $mrules_found); $mrules_criteria = [ 'FROM' => \RuleMatchedLog::getTable(), @@ -1229,40 +1245,40 @@ public function testUpdateComputer() $monitor_criteria = $mrules_criteria; $monitor_criteria['WHERE'] = ['itemtype' => \Monitor::getType()]; $iterator = $DB->request($monitor_criteria); - $this->integer(count($iterator))->isIdenticalTo(1); - $this->string($iterator->current()['name'])->isIdenticalTo('Monitor import (by serial)'); - $this->string($iterator->current()['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertCount(1, $iterator); + $this->assertSame('Monitor import (by serial)', $iterator->current()['name']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $iterator->current()['method']); $computer_criteria = $mrules_criteria; $computer_criteria['WHERE'] = ['itemtype' => \Computer::getType()]; $iterator = $DB->request($computer_criteria); - $this->integer(count($iterator))->isIdenticalTo(1); - $this->string($iterator->current()['name'])->isIdenticalTo('Computer import (by serial + uuid)'); - $this->integer($iterator->current()['items_id'])->isIdenticalTo($agent['items_id']); - $this->string($iterator->current()['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertCount(1, $iterator); + $this->assertSame('Computer import (by serial + uuid)', $iterator->current()['name']); + $this->assertSame($agent['items_id'], $iterator->current()['items_id']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $iterator->current()['method']); //get computer models, manufacturer, ... $autoupdatesystems = $DB->request(['FROM' => \AutoupdateSystem::getTable(), 'WHERE' => ['name' => 'GLPI Native Inventory']])->current(); - $this->array($autoupdatesystems); + $this->assertIsArray($autoupdatesystems); $autoupdatesystems_id = $autoupdatesystems['id']; $cmodels = $DB->request(['FROM' => \ComputerModel::getTable(), 'WHERE' => ['name' => 'PORTEGE Z30-A']])->current(); - $this->array($cmodels); + $this->assertIsArray($cmodels); $computermodels_id = $cmodels['id']; $ctypes = $DB->request(['FROM' => \ComputerType::getTable(), 'WHERE' => ['name' => 'Notebook']])->current(); - $this->array($ctypes); + $this->assertIsArray($ctypes); $computertypes_id = $ctypes['id']; $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Toshiba']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); $expected = [ 'id' => $computers_id, @@ -1296,7 +1312,8 @@ public function testUpdateComputer() 'last_inventory_update' => $computer->fields['last_inventory_update'], 'last_boot' => "2017-02-20 08:11:53", ]; - $this->array($computer->fields)->isIdenticalTo($expected); + $this->assertIsArray($computer->fields); + $this->assertSame($expected, $computer->fields); //operating system $ios = new \Item_OperatingSystem(); @@ -1310,12 +1327,13 @@ public function testUpdateComputer() 'architecture' => 'x86_64', 'servicepack' => null, ]; - $this->array($record)->isIdenticalTo($expected); + $this->assertIsArray($record); + $this->assertSame($expected, $record); //volumes $idisks = new \Item_Disk(); $iterator = $idisks->getFromItem($computer); - $this->integer(count($iterator))->isIdenticalTo(3); + $this->assertCount(3, $iterator); $expecteds_fs = [ [ @@ -1374,13 +1392,14 @@ public function testUpdateComputer() 'is_deleted' => 0, 'is_dynamic' => 1 ]; - $this->array($volume)->isEqualTo($expected); + $this->assertIsArray($volume); + $this->assertEquals($expected, $volume); ++$i; } //connections $iterator = \Computer_Item::getTypeItems($computers_id, 'Monitor'); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); //check network ports $iterator = $DB->request([ @@ -1390,7 +1409,7 @@ public function testUpdateComputer() 'itemtype' => 'Computer', ], ]); - $this->integer(count($iterator))->isIdenticalTo(4); + $this->assertCount(4, $iterator); //check for components $components = []; @@ -1429,14 +1448,14 @@ public function testUpdateComputer() ]; foreach ($expecteds_components as $type => $count) { - $this->integer(count($components[$type]))->isIdenticalTo($count, "$type " . count($components[$type])); + $this->assertCount($count, $components[$type], "$type " . count($components[$type])); } //check memory - $this->array($components['Item_DeviceMemory'])->hasSize(2); + $this->assertCount(2, $components['Item_DeviceMemory']); $mem_component1 = array_pop($components['Item_DeviceMemory']); $mem_component2 = array_pop($components['Item_DeviceMemory']); - $this->integer($mem_component1['devicememories_id'])->isGreaterThan(0); + $this->assertGreaterThan(0, $mem_component1['devicememories_id']); $expected_mem_component = [ 'items_id' => $mem_component1['items_id'], 'itemtype' => "Computer", @@ -1452,14 +1471,16 @@ public function testUpdateComputer() 'locations_id' => 0, 'states_id' => 0 ]; - $this->array($mem_component1)->isIdenticalTo($expected_mem_component); + $this->assertIsArray($mem_component1); + $this->assertSame($expected_mem_component, $mem_component1); $expected_mem_component['busID'] = "1"; - $this->array($mem_component2)->isIdenticalTo($expected_mem_component); + $this->assertIsArray($mem_component2); + $this->assertSame($expected_mem_component, $mem_component2); //software $isoft = new \Item_SoftwareVersion(); $iterator = $isoft->getFromItem($computer); - $this->integer(count($iterator))->isIdenticalTo(3034); + $this->assertCount(3034, $iterator); //computer has been created, check logs. //check for expected logs @@ -1469,13 +1490,13 @@ public function testUpdateComputer() 'LIMIT' => $nblogsnow, 'OFFSET' => $this->nblogs, ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //fake computer update (nothing has changed) $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_3.json')); $this->doInventory($json); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); $expected = [ 'id' => $computers_id, @@ -1509,7 +1530,8 @@ public function testUpdateComputer() 'last_inventory_update' => $computer->fields['last_inventory_update'], 'last_boot' => "2017-02-20 08:11:53", ]; - $this->array($computer->fields)->isIdenticalTo($expected); + $this->assertIsArray($computer->fields); + $this->assertSame($expected, $computer->fields); //operating system $ios = new \Item_OperatingSystem(); @@ -1523,12 +1545,13 @@ public function testUpdateComputer() 'architecture' => 'x86_64', 'servicepack' => null, ]; - $this->array($record)->isIdenticalTo($expected); + $this->assertIsArray($record); + $this->assertSame($expected, $record); //volumes $idisks = new \Item_Disk(); $iterator = $idisks->getFromItem($computer); - $this->integer(count($iterator))->isIdenticalTo(3); + $this->assertCount(3, $iterator); $i = 0; foreach ($iterator as $volume) { @@ -1543,13 +1566,14 @@ public function testUpdateComputer() 'is_deleted' => 0, 'is_dynamic' => 1 ]; - $this->array($volume)->isEqualTo($expected); + $this->assertIsArray($volume); + $this->assertEquals($expected, $volume); ++$i; } //connections $iterator = \Computer_Item::getTypeItems($computers_id, 'Monitor'); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); //check network ports $iterator = $DB->request([ @@ -1559,7 +1583,7 @@ public function testUpdateComputer() 'itemtype' => 'Computer', ], ]); - $this->integer(count($iterator))->isIdenticalTo(4); + $this->assertCount(4, $iterator); //check for components $components = []; @@ -1578,23 +1602,25 @@ public function testUpdateComputer() } foreach ($expecteds_components as $type => $count) { - $this->integer(count($components[$type]))->isIdenticalTo($count, "$type " . count($components[$type])); + $this->assertCount($count, $components[$type], "$type " . count($components[$type])); } //check memory - $this->array($components['Item_DeviceMemory'])->hasSize(2); + $this->assertCount(2, $components['Item_DeviceMemory']); $mem_component1 = array_pop($components['Item_DeviceMemory']); $mem_component2 = array_pop($components['Item_DeviceMemory']); - $this->integer($mem_component1['devicememories_id'])->isGreaterThan(0); + $this->assertGreaterThan(0, $mem_component1['devicememories_id']); $expected_mem_component['busID'] = "2"; - $this->array($mem_component1)->isIdenticalTo($expected_mem_component); + $this->assertIsArray($mem_component1); + $this->assertSame($expected_mem_component, $mem_component1); $expected_mem_component['busID'] = "1"; - $this->array($mem_component2)->isIdenticalTo($expected_mem_component); + $this->assertIsArray($mem_component2); + $this->assertSame($expected_mem_component, $mem_component2); //software $isoft = new \Item_SoftwareVersion(); $iterator = $isoft->getFromItem($computer); - $this->integer(count($iterator))->isIdenticalTo(3034); + $this->assertCount(3034, $iterator); //check for expected logs $nblogsnow = countElementsInTable(\Log::getTable()); @@ -1603,7 +1629,7 @@ public function testUpdateComputer() 'LIMIT' => $nblogsnow, 'OFFSET' => $this->nblogs, ]); - $this->integer(count($logs))->isIdenticalTo(0); + $this->assertCount(0, $logs); //real computer update $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_3_updated.json')); @@ -1612,31 +1638,30 @@ public function testUpdateComputer() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(7) - ->string['deviceid']->isIdenticalTo('LF014-2017-02-20-12-19-56') - ->string['version']->isIdenticalTo('FusionInventory-Agent_v2.3.20') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['tag']->isIdenticalTo('000005') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('inventory'); - ; - $this->array($metadata['provider'])->hasSize(9); + $this->assertCount(7, $metadata); + $this->assertSame('LF014-2017-02-20-12-19-56', $metadata['deviceid']); + $this->assertSame('FusionInventory-Agent_v2.3.20', $metadata['version']); + $this->assertSame('Computer', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('000005', $metadata['tag']); + $this->assertSame('inventory', $metadata['action']); + $this->assertCount(9, $metadata['provider']); //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('LF014-2017-02-20-12-19-56') - ->string['name']->isIdenticalTo('LF014-2017-02-20-12-19-56') - ->string['version']->isIdenticalTo('2.3.20') - ->string['itemtype']->isIdenticalTo('Computer') - ->integer['items_id']->isIdenticalTo($computers_id) - ->string['tag']->isIdenticalTo('000005') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']); + $this->assertIsArray($agent); + $this->assertSame('LF014-2017-02-20-12-19-56', $agent['deviceid']); + $this->assertSame('LF014-2017-02-20-12-19-56', $agent['name']); + $this->assertSame('2.3.20', $agent['version']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame($computers_id, $agent['items_id']); + $this->assertSame('000005', $agent['tag']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); $expected = [ 'id' => $computers_id, @@ -1670,7 +1695,8 @@ public function testUpdateComputer() 'last_inventory_update' => $computer->fields['last_inventory_update'], 'last_boot' => "2017-06-08 07:06:47", ]; - $this->array($computer->fields)->isIdenticalTo($expected); + $this->assertIsArray($computer->fields); + $this->assertSame($expected, $computer->fields); //operating system $ios = new \Item_OperatingSystem(); @@ -1684,12 +1710,13 @@ public function testUpdateComputer() 'architecture' => 'x86_64', 'servicepack' => null, ]; - $this->array($record)->isIdenticalTo($expected); + $this->assertIsArray($record); + $this->assertSame($expected, $record); //volumes $idisks = new \Item_Disk(); $iterator = $idisks->getFromItem($computer); - $this->integer(count($iterator))->isIdenticalTo(3); + $this->assertCount(3, $iterator); //update fs values $expecteds_fs[0]['totalsize'] = 150268; @@ -1710,13 +1737,14 @@ public function testUpdateComputer() 'is_deleted' => 0, 'is_dynamic' => 1 ]; - $this->array($volume)->isEqualTo($expected); + $this->assertIsArray($volume); + $this->assertEquals($expected, $volume); ++$i; } //connections $iterator = \Computer_Item::getTypeItems($computers_id, 'Monitor'); - $this->integer(count($iterator))->isIdenticalTo(0); + $this->assertCount(0, $iterator); //check network ports $iterator = $DB->request([ @@ -1726,7 +1754,7 @@ public function testUpdateComputer() 'itemtype' => 'Computer', ], ]); - $this->integer(count($iterator))->isIdenticalTo(7); + $this->assertCount(7, $iterator); //check for components $components = []; @@ -1745,11 +1773,11 @@ public function testUpdateComputer() } foreach ($expecteds_components as $type => $count) { - $this->integer(count($components[$type]))->isIdenticalTo($count, "$type " . count($components[$type])); + $this->assertCount($count, $components[$type], "$type " . count($components[$type])); } //check memory - $this->array($components['Item_DeviceMemory'])->hasSize(2); + $this->assertCount(2, $components['Item_DeviceMemory']); $mem_component1 = array_pop($components['Item_DeviceMemory']); $mem_component2 = array_pop($components['Item_DeviceMemory']); $expected_mem_component = [ @@ -1767,14 +1795,16 @@ public function testUpdateComputer() 'locations_id' => 0, 'states_id' => 0 ]; - $this->array($mem_component1)->isIdenticalTo($expected_mem_component); + $this->assertIsArray($mem_component1); + $this->assertSame($expected_mem_component, $mem_component1); $expected_mem_component['busID'] = "1"; - $this->array($mem_component2)->isIdenticalTo($expected_mem_component); + $this->assertIsArray($mem_component2); + $this->assertSame($expected_mem_component, $mem_component2); //software $isoft = new \Item_SoftwareVersion(); $iterator = $isoft->getFromItem($computer); - $this->integer(count($iterator))->isIdenticalTo(3185); + $this->assertCount(3185, $iterator); //check for expected logs after update $logs = $DB->request([ @@ -1783,7 +1813,7 @@ public function testUpdateComputer() 'OFFSET' => $nblogsnow, ]); - $this->integer(count($logs))->isIdenticalTo(4418); + $this->assertCount(4418, $logs); $expected_types_count = [ 0 => 3, //Agent version, disks usage @@ -1800,7 +1830,7 @@ public function testUpdateComputer() $types_count = []; foreach ($logs as $row) { - $this->string($row['user_name'])->isIdenticalTo('inventory', print_r($row, true)); + $this->assertSame('inventory', $row['user_name'], print_r($row, true)); if (!isset($types_count[$row['linked_action']])) { $types_count[$row['linked_action']] = 0; } @@ -1809,8 +1839,9 @@ public function testUpdateComputer() ksort($types_count); ksort($expected_types_count); - $this->array($types_count)->isEqualTo( + $this->assertEquals( $expected_types_count, + $types_count, sprintf( "\nGot:\n%s\n\nExpected:\n%s", print_r($types_count, true), @@ -1822,24 +1853,24 @@ public function testUpdateComputer() $mlogs = new \RuleMatchedLog(); $found = $mlogs->find(['NOT' => ['id' => array_keys($mrules_found)]]); $mrules_criteria['WHERE'] = ['NOT' => [\RuleMatchedLog::getTable() . '.id' => array_keys($mrules_found)]]; - $this->array($found)->hasSize(3); + $this->assertCount(3, $found); $monitor_criteria = $mrules_criteria; $monitor_criteria['WHERE'][] = ['itemtype' => \Monitor::getType()]; $iterator = $DB->request($monitor_criteria); - $this->integer(count($iterator))->isIdenticalTo(1); - $this->string($iterator->current()['name'])->isIdenticalTo('Monitor update (by serial)'); - $this->string($iterator->current()['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertCount(1, $iterator); + $this->assertSame('Monitor update (by serial)', $iterator->current()['name']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $iterator->current()['method']); $computer_criteria = $mrules_criteria; $computer_criteria['WHERE'][] = ['itemtype' => \Computer::getType()]; $iterator = $DB->request($computer_criteria); - $this->integer(count($iterator))->isIdenticalTo(2); + $this->assertCount(2, $iterator); foreach ($iterator as $rmlog) { - $this->string($rmlog['name'])->isIdenticalTo('Computer update (by serial + uuid)'); - $this->integer($rmlog['items_id'])->isIdenticalTo($agent['items_id']); - $this->string($rmlog['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertSame('Computer update (by serial + uuid)', $rmlog['name']); + $this->assertSame($agent['items_id'], $rmlog['items_id']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $rmlog['method']); } } @@ -1854,49 +1885,49 @@ public function testImportNetworkEquipment() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(5) - ->string['deviceid']->isIdenticalTo('foo') - ->string['version']->isIdenticalTo('4.1') - ->string['itemtype']->isIdenticalTo('NetworkEquipment') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('netinventory'); + $this->assertCount(5, $metadata); + $this->assertSame('foo', $metadata['deviceid']); + $this->assertSame('4.1', $metadata['version']); + $this->assertSame('NetworkEquipment', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('netinventory', $metadata['action']); global $DB; //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); //no agent with deviceid equals to "foo" - $this->integer(count($agents))->isIdenticalTo(0); + $this->assertCount(0, $agents); //get model, manufacturer, ... $autoupdatesystems = $DB->request(['FROM' => \AutoupdateSystem::getTable(), 'WHERE' => ['name' => 'GLPI Native Inventory']])->current(); - $this->array($autoupdatesystems); + $this->assertIsArray($autoupdatesystems); $autoupdatesystems_id = $autoupdatesystems['id']; $cmodels = $DB->request(['FROM' => \NetworkEquipmentModel::getTable(), 'WHERE' => ['name' => 'UCS 6248UP 48-Port']])->current(); - $this->array($cmodels); + $this->assertIsArray($cmodels); $models_id = $cmodels['id']; $ctypes = $DB->request(['FROM' => \NetworkEquipmentType::getTable(), 'WHERE' => ['name' => 'Networking']])->current(); - $this->array($ctypes); + $this->assertIsArray($ctypes); $types_id = $ctypes['id']; $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Cisco']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $cloc = $DB->request(['FROM' => \Location::getTable(), 'WHERE' => ['name' => 'paris.pa3']])->current(); - $this->array($cloc); + $this->assertIsArray($cloc); $locations_id = $cloc['id']; //check created asset $equipments = $DB->request(['FROM' => \NetworkEquipment::getTable(), 'WHERE' => ['is_dynamic' => 1]]); //no agent with deviceid equals to "foo" - $this->integer(count($equipments))->isIdenticalTo(1); + $this->assertCount(1, $equipments); $equipments_id = $equipments->current()['id']; $equipment = new \NetworkEquipment(); - $this->boolean($equipment->getFromDB($equipments_id))->isTrue(); + $this->assertTrue($equipment->getFromDB($equipments_id)); $expected = [ 'id' => $equipments_id, @@ -1934,7 +1965,8 @@ public function testImportNetworkEquipment() 'last_inventory_update' => $date_now, 'snmpcredentials_id' => 4, ]; - $this->array($equipment->fields)->isIdenticalTo($expected); + $this->assertIsArray($equipment->fields); + $this->assertSame($expected, $equipment->fields); //check network ports $expected_count = 164; @@ -1945,7 +1977,7 @@ public function testImportNetworkEquipment() 'itemtype' => 'NetworkEquipment', ], ]); - $this->integer(count($iterator))->isIdenticalTo($expected_count); + $this->assertCount($expected_count, $iterator); $expecteds = [ ($expected_count - 1) => [ @@ -1967,12 +1999,12 @@ public function testImportNetworkEquipment() $netport = new \NetworkPort(); foreach ($iterator as $port) { $ports_id = $port['id']; - $this->boolean($netport->getFromDB($ports_id))->isTrue(); + $this->assertTrue($netport->getFromDB($ports_id)); $instantiation = $netport->getInstantiation(); if ($port['instantiation_type'] === null) { - $this->boolean($instantiation)->isFalse(); + $this->assertFalse($instantiation); } else { - $this->object($instantiation)->isInstanceOf($port['instantiation_type']); + $this->assertInstanceOf($port['instantiation_type'], $instantiation); } unset($port['id']); @@ -2006,13 +2038,17 @@ public function testImportNetworkEquipment() 'lastup' => null ]; - $this->array($port)->isEqualTo($expected); + $this->assertIsArray($port); + $this->assertEquals($expected, $port); } else { - $this->string($port['itemtype'])->isIdenticalTo('NetworkEquipment'); - $this->integer($port['items_id'])->isIdenticalTo($equipments_id); - $this->string($port['instantiation_type'])->isIdenticalTo('NetworkPortEthernet', print_r($port, true)); - $this->string($port['mac'])->matches('/^(?:(?:[0-9a-f]{2}[\:]{1}){5}|(?:[0-9a-f]{2}[-]{1}){5}|(?:[0-9a-f]{2}){5})[0-9a-f]{2}$/i'); - $this->integer($port['is_dynamic'])->isIdenticalTo(1); + $this->assertSame('NetworkEquipment', $port['itemtype']); + $this->assertSame($equipments_id, $port['items_id']); + $this->assertSame('NetworkPortEthernet', $port['instantiation_type'], print_r($port, true),); + $this->assertMatchesRegularExpression( + '/^(?:(?:[0-9a-f]{2}[\:]{1}){5}|(?:[0-9a-f]{2}[-]{1}){5}|(?:[0-9a-f]{2}){5})[0-9a-f]{2}$/i', + $port['mac'] + ); + $this->assertSame(1, $port['is_dynamic']); } ++$i; @@ -2039,10 +2075,11 @@ public function testImportNetworkEquipment() ] ]); - $this->integer(count($ip_iterator))->isIdenticalTo(count($ips[$port['name']] ?? [])); + $this->assertCount(count($ips[$port['name']] ?? []), $ip_iterator); if (isset($ips[$port['name']])) { foreach ($ip_iterator as $ip) { - $this->array($ips[$port['name']])->contains($ip['name']); + $this->assertIsArray($ips[$port['name']]); + $this->assertTrue(in_array($ip['name'], $ips[$port['name']])); } } } @@ -2075,8 +2112,9 @@ public function testImportNetworkEquipment() ]; foreach ($expecteds as $type => $count) { - $this->integer(count($components[$type]))->isIdenticalTo( + $this->assertSame( $count, + count($components[$type]), sprintf( 'Expected %1$s %2$s, got %3$s of them', $count, @@ -2121,16 +2159,17 @@ public function testImportNetworkEquipment() } } } - $this->array($component)->isIdenticalTo($expected); + $this->assertIsArray($component); + $this->assertSame($expected, $component); } //ports connections $connections = $DB->request(['FROM' => \NetworkPort_NetworkPort::getTable()]); - $this->integer(count($connections))->isIdenticalTo(5); + $this->assertCount(5, $connections); //unmanaged equipments $unmanageds = $DB->request(['FROM' => \Unmanaged::getTable()]); - $this->integer(count($unmanageds))->isIdenticalTo(5); + $this->assertCount(5, $unmanageds); $expecteds = [ 'sw2-mgmt-eqnx' => "Cisco IOS Software, C2960 Software (C2960-LANLITEK9-M), Version 12.2(50)SE5, RELEASE SOFTWARE (fc1) @@ -2142,14 +2181,14 @@ public function testImportNetworkEquipment() ]; foreach ($unmanageds as $unmanaged) { - $this->boolean(in_array($unmanaged['name'], array_keys($expecteds)))->isTrue($unmanaged['name']); - $this->string($unmanaged['sysdescr'])->isIdenticalTo($expecteds[$unmanaged['name']]); + $this->assertTrue(in_array($unmanaged['name'], array_keys($expecteds)), $unmanaged['name']); + $this->assertSame($expecteds[$unmanaged['name']], $unmanaged['sysdescr']); } //check matchedlogs $mlogs = new \RuleMatchedLog(); $found = $mlogs->find(); - $this->array($found)->hasSize(6);//1 equipment, 5 unmanageds + $this->assertCount(6, $found);//1 equipment, 5 unmanageds $mrules_criteria = [ 'FROM' => \RuleMatchedLog::getTable(), @@ -2167,20 +2206,20 @@ public function testImportNetworkEquipment() $neteq_criteria = $mrules_criteria; $neteq_criteria['WHERE'][] = ['itemtype' => \NetworkEquipment::getType()]; $iterator = $DB->request($neteq_criteria); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); foreach ($iterator as $neteq) { - $this->string($neteq['name'])->isIdenticalTo('NetworkEquipment import (by serial)'); - $this->integer($neteq['items_id'])->isIdenticalTo($equipments_id); - $this->string($neteq['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertSame('NetworkEquipment import (by serial)', $neteq['name']); + $this->assertSame($equipments_id, $neteq['items_id']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $neteq['method']); } $unmanaged_criteria = $mrules_criteria; $unmanaged_criteria['WHERE'][] = ['itemtype' => \Unmanaged::getType()]; $iterator = $DB->request($unmanaged_criteria); - $this->integer(count($iterator))->isIdenticalTo(5); + $this->assertCount(5, $iterator); foreach ($iterator as $unmanaged) { - $this->string($unmanaged['name'])->isIdenticalTo('Global import (by ip+ifdescr)'); - $this->string($unmanaged['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertSame('Global import (by ip+ifdescr)', $unmanaged['name']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $unmanaged['method']); } } @@ -2195,42 +2234,41 @@ public function testImportStackedNetworkEquipment() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(5) - ->string['deviceid']->isIdenticalTo('3k-1-pa3.glpi-project.infra-2020-12-31-11-28-51') - ->string['version']->isIdenticalTo('4.1') - ->string['itemtype']->isIdenticalTo('NetworkEquipment') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('netinventory'); + $this->assertCount(5, $metadata); + $this->assertSame('3k-1-pa3.glpi-project.infra-2020-12-31-11-28-51', $metadata['deviceid']); + $this->assertSame('4.1', $metadata['version']); + $this->assertSame('NetworkEquipment', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('netinventory', $metadata['action']); global $DB; //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); - $this->array($inventory->getAgent()->fields) - ->string['deviceid']->isIdenticalTo('3k-1-pa3.glpi-project.infra-2020-12-31-11-28-51') - ->string['name']->isIdenticalTo('3k-1-pa3.glpi-project.infra-2020-12-31-11-28-51') - //->string['version']->isIdenticalTo('') - ->string['itemtype']->isIdenticalTo('NetworkEquipment') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']); + $this->assertIsArray($inventory->getAgent()->fields); + $this->assertSame('3k-1-pa3.glpi-project.infra-2020-12-31-11-28-51', $inventory->getAgent()->fields['deviceid']); + $this->assertSame('3k-1-pa3.glpi-project.infra-2020-12-31-11-28-51', $inventory->getAgent()->fields['name']); + $this->assertSame('NetworkEquipment', $inventory->getAgent()->fields['itemtype']); + $this->assertSame($agenttype['id'], $inventory->getAgent()->fields['agenttypes_id']); //get model, manufacturer, ... $autoupdatesystems = $DB->request(['FROM' => \AutoupdateSystem::getTable(), 'WHERE' => ['name' => 'GLPI Native Inventory']])->current(); - $this->array($autoupdatesystems); + $this->assertIsArray($autoupdatesystems); $autoupdatesystems_id = $autoupdatesystems['id']; $cmodels = $DB->request(['FROM' => \NetworkEquipmentModel::getTable(), 'WHERE' => ['name' => 'WS-C3750G-48TS-S']])->current(); - $this->array($cmodels); + $this->assertIsArray($cmodels); $models_id = $cmodels['id']; $ctypes = $DB->request(['FROM' => \NetworkEquipmentType::getTable(), 'WHERE' => ['name' => 'Networking']])->current(); - $this->array($ctypes); + $this->assertIsArray($ctypes); $types_id = $ctypes['id']; $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Cisco']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $cloc = $DB->request(['FROM' => \Location::getTable(), 'WHERE' => ['name' => 'paris.pa3']])->current(); - $this->array($cloc); + $this->assertIsArray($cloc); $locations_id = $cloc['id']; //check created equipments @@ -2239,7 +2277,7 @@ public function testImportStackedNetworkEquipment() 'FROM' => \NetworkEquipment::getTable(), 'WHERE' => ['is_dynamic' => 1] ]); - $this->integer(count($iterator))->isIdenticalTo($expected_eq_count); + $this->assertCount($expected_eq_count, $iterator); $main_expected = [ 'id' => null, @@ -2306,14 +2344,16 @@ public function testImportStackedNetworkEquipment() $equipments_id = $row['id']; $expected['id'] = $equipments_id; $equipment = new \NetworkEquipment(); - $this->boolean($equipment->getFromDB($equipments_id))->isTrue(); + $this->assertTrue($equipment->getFromDB($equipments_id)); $expected['date_mod'] = $row['date_mod']; $expected['date_creation'] = $row['date_creation']; $stack_id = preg_replace('/.+ - (\d)/', '$1', $row['name']); - $this->array($stacks)->hasKey($stack_id); + $this->assertIsArray($stacks); + $this->assertArrayHasKey($stack_id, $stacks); $expected['name'] .= ' - ' . $stack_id; $expected['serial'] = $stacks[$stack_id]['serial']; - $this->array($row)->isIdenticalTo($expected); + $this->assertIsArray($row); + $this->assertSame($expected, $row); //check network ports $expected_count = 53; @@ -2324,8 +2364,9 @@ public function testImportStackedNetworkEquipment() 'itemtype' => 'NetworkEquipment', ], ]); - $this->integer(count($ports_iterator))->isIdenticalTo( + $this->assertSame( $expected_count, + count($ports_iterator), sprintf( '%s ports found on %s, %s expected', count($ports_iterator), @@ -2383,12 +2424,12 @@ public function testImportStackedNetworkEquipment() foreach ($ports_iterator as $port) { $ports_id = $port['id']; $all_ports_ids[] = $port['id']; - $this->boolean($netport->getFromDB($ports_id))->isTrue(); + $this->assertTrue($netport->getFromDB($ports_id)); $instantiation = $netport->getInstantiation(); if ($port['instantiation_type'] === null) { - $this->boolean($instantiation)->isFalse(); + $this->assertFalse($instantiation); } else { - $this->object($instantiation)->isInstanceOf($port['instantiation_type']); + $this->assertInstanceOf($port['instantiation_type'], $instantiation); } unset($port['id']); @@ -2422,13 +2463,17 @@ public function testImportStackedNetworkEquipment() 'lastup' => null ]; - $this->array($port)->isEqualTo($expected); + $this->assertIsArray($port); + $this->assertEquals($expected, $port); } else { - $this->string($port['itemtype'])->isIdenticalTo('NetworkEquipment'); - $this->integer($port['items_id'])->isIdenticalTo($equipments_id); - $this->string($port['instantiation_type'])->isIdenticalTo('NetworkPortEthernet', print_r($port, true)); - $this->string($port['mac'])->matches('/^(?:(?:[0-9a-f]{2}[\:]{1}){5}|(?:[0-9a-f]{2}[-]{1}){5}|(?:[0-9a-f]{2}){5})[0-9a-f]{2}$/i'); - $this->integer($port['is_dynamic'])->isIdenticalTo(1); + $this->assertSame('NetworkEquipment', $port['itemtype']); + $this->assertSame($equipments_id, $port['items_id']); + $this->assertSame('NetworkPortEthernet', $port['instantiation_type'], print_r($port, true)); + $this->assertMatchesRegularExpression( + '/^(?:(?:[0-9a-f]{2}[\:]{1}){5}|(?:[0-9a-f]{2}[-]{1}){5}|(?:[0-9a-f]{2}){5})[0-9a-f]{2}$/i', + $port['mac'] + ); + $this->assertSame(1, $port['is_dynamic']); } ++$i; @@ -2455,10 +2500,11 @@ public function testImportStackedNetworkEquipment() ] ]); - $this->integer(count($ip_iterator))->isIdenticalTo(count($ips[$port['name']] ?? [])); + $this->assertCount(count($ips[$port['name']] ?? []), $ip_iterator); if (isset($ips[$port['name']])) { foreach ($ip_iterator as $ip) { - $this->array($ips[$port['name']])->contains($ip['name']); + $this->assertIsArray($ips[$port['name']]); + $this->assertTrue(in_array($ip['name'], $ips[$port['name']])); } } } @@ -2491,8 +2537,9 @@ public function testImportStackedNetworkEquipment() ]; foreach ($expecteds as $type => $count) { - $this->integer(count($components[$type]))->isIdenticalTo( + $this->assertSame( $count, + count($components[$type]), sprintf( 'Expected %1$s %2$s, got %3$s of them', $count, @@ -2537,7 +2584,8 @@ public function testImportStackedNetworkEquipment() } } } - $this->array($component)->isIdenticalTo($expected); + $this->assertIsArray($component); + $this->assertSame($expected, $component); } //ports connections @@ -2548,8 +2596,9 @@ public function testImportStackedNetworkEquipment() ] ]); - $this->integer(count($connections))->isIdenticalTo( + $this->assertSame( $stacks[$stack_id]['connections'], + count($connections), sprintf( '%s connections found on stack %s, %s expected', count($connections), @@ -2560,19 +2609,19 @@ public function testImportStackedNetworkEquipment() } $db_ports = $DB->request(['FROM' => \NetworkPort::getTable()]); - $this->integer(count($db_ports))->isIdenticalTo(325); + $this->assertCount(325, $db_ports); $db_neteq_ports = $DB->request(['FROM' => \NetworkPort::getTable(), 'WHERE' => ['itemtype' => 'NetworkEquipment']]); - $this->integer(count($db_neteq_ports))->isIdenticalTo(265); + $this->assertCount(265, $db_neteq_ports); $db_connections = $DB->request(['FROM' => \NetworkPort_NetworkPort::getTable()]); - $this->integer(count($db_connections))->isIdenticalTo(26); + $this->assertCount(26, $db_connections); $db_unmanageds = $DB->request(['FROM' => \Unmanaged::getTable()]); - $this->integer(count($db_unmanageds))->isIdenticalTo(45); + $this->assertCount(45, $db_unmanageds); $db_ips = $DB->request(['FROM' => \IPAddress::getTable()]); - $this->integer(count($db_ips))->isIdenticalTo(150); + $this->assertCount(150, $db_ips); $expected_names = [ 'san-replication', @@ -2589,19 +2638,19 @@ public function testImportStackedNetworkEquipment() '0001-pub' ]; $db_vlans = $DB->request(['FROM' => \Vlan::getTable()]); - $this->integer(count($db_vlans))->isIdenticalTo(count($expected_names)); + $this->assertCount(count($expected_names), $db_vlans); $i = 0; foreach ($db_vlans as $row) { - $this->string($row['name'])->isEqualTo($expected_names[$i]); + $this->assertSame($expected_names[$i], $row['name']); ++$i; } $db_vlans_ports = $DB->request(['FROM' => \NetworkPort_Vlan::getTable()]); - $this->integer(count($db_vlans_ports))->isIdenticalTo(219); + $this->assertCount(219, $db_vlans_ports); $db_netnames = $DB->request(['FROM' => \NetworkName::getTable()]); - $this->integer(count($db_netnames))->isIdenticalTo(10); + $this->assertCount(10, $db_netnames); $expecteds = [ [ @@ -2635,7 +2684,7 @@ public function testImportStackedNetworkEquipment() $i = 0; /*foreach ($unmanageds as $unmanaged) { foreach ($expecteds[$i] as $key => $value) { - $this->variable($unmanaged[$key])->isEqualTo($value); + $this->>assertEquals($value, $unmanaged[$key]); } ++$i; }*/ @@ -2643,7 +2692,7 @@ public function testImportStackedNetworkEquipment() //check matchedlogs $mlogs = new \RuleMatchedLog(); $found = $mlogs->find(); - $this->array($found)->hasSize(48); + $this->assertCount(48, $found); $mrules_criteria = [ 'FROM' => \RuleMatchedLog::getTable(), @@ -2661,16 +2710,16 @@ public function testImportStackedNetworkEquipment() $neteq_criteria = $mrules_criteria; $neteq_criteria['WHERE'][] = ['itemtype' => \NetworkEquipment::getType()]; $iterator = $DB->request($neteq_criteria); - $this->integer(count($iterator))->isIdenticalTo($expected_eq_count); + $this->assertCount($expected_eq_count, $iterator); foreach ($iterator as $neteq) { - $this->string($neteq['name'])->isIdenticalTo('NetworkEquipment import (by serial)'); - $this->string($neteq['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertSame('NetworkEquipment import (by serial)', $neteq['name']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $neteq['method']); } $unmanaged_criteria = $mrules_criteria; $unmanaged_criteria['WHERE'][] = ['itemtype' => \Unmanaged::getType()]; $iterator = $DB->request($unmanaged_criteria); - $this->integer(count($iterator))->isIdenticalTo(43); + $this->assertCount(43, $iterator); } public function testImportStackedNetworkEquipment2() @@ -2684,41 +2733,40 @@ public function testImportStackedNetworkEquipment2() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(5) - ->string['deviceid']->isIdenticalTo('it-2024-05-11-14-34-10') - ->string['version']->isIdenticalTo('6.1') - ->string['itemtype']->isIdenticalTo('NetworkEquipment') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('netinventory'); + $this->assertCount(5, $metadata); + $this->assertSame('it-2024-05-11-14-34-10', $metadata['deviceid']); + $this->assertSame('6.1', $metadata['version']); + $this->assertSame('NetworkEquipment', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('netinventory', $metadata['action']); global $DB; //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); - $this->array($inventory->getAgent()->fields) - ->string['deviceid']->isIdenticalTo('it-2024-05-11-14-34-10') - ->string['name']->isIdenticalTo('it-2024-05-11-14-34-10') - ->string['itemtype']->isIdenticalTo('NetworkEquipment') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']); + $this->assertSame('it-2024-05-11-14-34-10', $inventory->getAgent()->fields['deviceid']); + $this->assertSame('it-2024-05-11-14-34-10', $inventory->getAgent()->fields['name']); + $this->assertSame('NetworkEquipment', $inventory->getAgent()->fields['itemtype']); + $this->assertSame($agenttype['id'], $inventory->getAgent()->fields['agenttypes_id']); //get model, manufacturer, ... $autoupdatesystems = $DB->request(['FROM' => \AutoupdateSystem::getTable(), 'WHERE' => ['name' => 'GLPI Native Inventory']])->current(); - $this->array($autoupdatesystems); + $this->assertIsArray($autoupdatesystems); $autoupdatesystems_id = $autoupdatesystems['id']; $cmodels = $DB->request(['FROM' => \NetworkEquipmentModel::getTable(), 'WHERE' => ['name' => 'JG937A']])->current(); - $this->array($cmodels); + $this->assertIsArray($cmodels); $models_id = $cmodels['id']; $ctypes = $DB->request(['FROM' => \NetworkEquipmentType::getTable(), 'WHERE' => ['name' => 'Networking']])->current(); - $this->array($ctypes); + $this->assertIsArray($ctypes); $types_id = $ctypes['id']; $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Hewlett-Packard']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $cloc = $DB->request(['FROM' => \Location::getTable(), 'WHERE' => ['name' => 'office']])->current(); - $this->array($cloc); + $this->assertIsArray($cloc); $locations_id = $cloc['id']; //check created equipments @@ -2727,7 +2775,7 @@ public function testImportStackedNetworkEquipment2() 'FROM' => \NetworkEquipment::getTable(), 'WHERE' => ['is_dynamic' => 1] ]); - $this->integer(count($iterator))->isIdenticalTo($expected_eq_count); + $this->assertCount($expected_eq_count, $iterator); $main_expected = [ 'id' => null, @@ -2784,20 +2832,22 @@ public function testImportStackedNetworkEquipment2() $equipments_id = $row['id']; $expected['id'] = $equipments_id; $equipment = new \NetworkEquipment(); - $this->boolean($equipment->getFromDB($equipments_id))->isTrue(); + $this->assertTrue($equipment->getFromDB($equipments_id)); $expected['date_mod'] = $row['date_mod']; $expected['date_creation'] = $row['date_creation']; $stack_id = preg_replace('/.+ - (\d)/', '$1', $row['name']); - $this->array($stacks)->hasKey($stack_id); + $this->assertIsArray($stacks); + $this->assertArrayHasKey($stack_id, $stacks); $expected['name'] .= ' - ' . $stack_id; $expected['serial'] = $stacks[$stack_id]['serial']; - $this->array($row)->isIdenticalTo($expected); + $this->assertIsArray($row); + $this->assertSame($expected, $row); } //check matchedlogs $mlogs = new \RuleMatchedLog(); $found = $mlogs->find(); - $this->array($found)->hasSize(2); + $this->assertCount(2, $found); $mrules_criteria = [ 'FROM' => \RuleMatchedLog::getTable(), @@ -2815,10 +2865,10 @@ public function testImportStackedNetworkEquipment2() $neteq_criteria = $mrules_criteria; $neteq_criteria['WHERE'][] = ['itemtype' => \NetworkEquipment::getType()]; $iterator = $DB->request($neteq_criteria); - $this->integer(count($iterator))->isIdenticalTo($expected_eq_count); + $this->assertCount($expected_eq_count, $iterator); foreach ($iterator as $neteq) { - $this->string($neteq['name'])->isIdenticalTo('NetworkEquipment import (by serial)'); - $this->string($neteq['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertSame('NetworkEquipment import (by serial)', $neteq['name']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $neteq['method']); } } public function testImportNetworkEquipmentMultiConnections() @@ -2832,37 +2882,36 @@ public function testImportNetworkEquipmentMultiConnections() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(5) - ->string['deviceid']->isIdenticalTo('HP-2530-48G-2020-12-31-11-28-51') - ->string['version']->isIdenticalTo('2.5') - ->string['itemtype']->isIdenticalTo('NetworkEquipment') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('netinventory'); + $this->assertCount(5, $metadata); + $this->assertSame('HP-2530-48G-2020-12-31-11-28-51', $metadata['deviceid']); + $this->assertSame('2.5', $metadata['version']); + $this->assertSame('NetworkEquipment', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('netinventory', $metadata['action']); global $DB; //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); - $this->array($inventory->getAgent()->fields) - ->string['deviceid']->isIdenticalTo('HP-2530-48G-2020-12-31-11-28-51') - ->string['name']->isIdenticalTo('HP-2530-48G-2020-12-31-11-28-51') - ->string['itemtype']->isIdenticalTo('NetworkEquipment') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']); + $this->assertSame('HP-2530-48G-2020-12-31-11-28-51', $inventory->getAgent()->fields['deviceid']); + $this->assertSame('HP-2530-48G-2020-12-31-11-28-51', $inventory->getAgent()->fields['name']); + $this->assertSame('NetworkEquipment', $inventory->getAgent()->fields['itemtype']); + $this->assertSame($agenttype['id'], $inventory->getAgent()->fields['agenttypes_id']); //get model, manufacturer, ... $autoupdatesystems = $DB->request(['FROM' => \AutoupdateSystem::getTable(), 'WHERE' => ['name' => 'GLPI Native Inventory']])->current(); - $this->array($autoupdatesystems); + $this->assertIsArray($autoupdatesystems); $autoupdatesystems_id = $autoupdatesystems['id']; $cmodels = $DB->request(['FROM' => \NetworkEquipmentModel::getTable(), 'WHERE' => ['name' => '2530-48G']])->current(); - $this->array($cmodels); + $this->assertIsArray($cmodels); $models_id = $cmodels['id']; $ctypes = $DB->request(['FROM' => \NetworkEquipmentType::getTable(), 'WHERE' => ['name' => 'Networking']])->current(); - $this->array($ctypes); + $this->assertIsArray($ctypes); $types_id = $ctypes['id']; $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Hewlett-Packard']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $locations_id = 0; @@ -2872,7 +2921,7 @@ public function testImportNetworkEquipmentMultiConnections() 'FROM' => \NetworkEquipment::getTable(), 'WHERE' => ['is_dynamic' => 1] ]); - $this->integer(count($iterator))->isIdenticalTo($expected_count); + $this->assertCount($expected_count, $iterator); $expected = [ 'id' => null, @@ -2915,10 +2964,11 @@ public function testImportNetworkEquipmentMultiConnections() $equipments_id = $row['id']; $expected['id'] = $equipments_id; $equipment = new \NetworkEquipment(); - $this->boolean($equipment->getFromDB($equipments_id))->isTrue(); + $this->assertTrue($equipment->getFromDB($equipments_id)); $expected['date_mod'] = $row['date_mod']; $expected['date_creation'] = $row['date_creation']; - $this->array($row)->isIdenticalTo($expected); + $this->assertIsArray($row); + $this->assertSame($expected, $row); //check network ports $expected_count = 53; @@ -2929,8 +2979,9 @@ public function testImportNetworkEquipmentMultiConnections() 'itemtype' => 'NetworkEquipment', ], ]); - $this->integer(count($ports_iterator))->isIdenticalTo( + $this->assertSame( $expected_count, + count($ports_iterator), sprintf( '%s ports found on %s, %s expected', count($ports_iterator), @@ -2960,12 +3011,12 @@ public function testImportNetworkEquipmentMultiConnections() foreach ($ports_iterator as $port) { $ports_id = $port['id']; $all_ports_ids[] = $port['id']; - $this->boolean($netport->getFromDB($ports_id))->isTrue(); + $this->assertTrue($netport->getFromDB($ports_id)); $instantiation = $netport->getInstantiation(); if ($port['instantiation_type'] === null) { - $this->boolean($instantiation)->isFalse(); + $this->assertFalse($instantiation); } else { - $this->object($instantiation)->isInstanceOf($port['instantiation_type']); + $this->assertInstanceOf($port['instantiation_type'], $instantiation); } unset($port['id']); @@ -2999,13 +3050,17 @@ public function testImportNetworkEquipmentMultiConnections() 'lastup' => null ]; - $this->array($port)->isEqualTo($expected); + $this->assertIsArray($port); + $this->assertEquals($expected, $port); } else { - $this->string($port['itemtype'])->isIdenticalTo('NetworkEquipment'); - $this->integer($port['items_id'])->isIdenticalTo($equipments_id); - $this->string($port['instantiation_type'])->isIdenticalTo('NetworkPortEthernet', print_r($port, true)); - $this->string($port['mac'])->matches('/^(?:(?:[0-9a-f]{2}[\:]{1}){5}|(?:[0-9a-f]{2}[-]{1}){5}|(?:[0-9a-f]{2}){5})[0-9a-f]{2}$/i'); - $this->integer($port['is_dynamic'])->isIdenticalTo(1); + $this->assertSame('NetworkEquipment', $port['itemtype']); + $this->assertSame($equipments_id, $port['items_id']); + $this->assertSame('NetworkPortEthernet', $port['instantiation_type'], print_r($port, true)); + $this->assertMatchesRegularExpression( + '/^(?:(?:[0-9a-f]{2}[\:]{1}){5}|(?:[0-9a-f]{2}[-]{1}){5}|(?:[0-9a-f]{2}){5})[0-9a-f]{2}$/i', + $port['mac'] + ); + $this->assertSame(1, $port['is_dynamic']); } ++$i; @@ -3032,10 +3087,11 @@ public function testImportNetworkEquipmentMultiConnections() ] ]); - $this->integer(count($ip_iterator))->isIdenticalTo(count($ips[$port['name']] ?? [])); + $this->assertCount(count($ips[$port['name']] ?? []), $ip_iterator); if (isset($ips[$port['name']])) { foreach ($ip_iterator as $ip) { - $this->array($ips[$port['name']])->contains($ip['name']); + $this->assertIsArray($ips[$port['name']]); + $this->assertTrue(in_array($ip['name'], $ips[$port['name']])); } } } @@ -3068,8 +3124,9 @@ public function testImportNetworkEquipmentMultiConnections() ]; foreach ($expecteds as $type => $count) { - $this->integer(count($components[$type]))->isIdenticalTo( + $this->assertSame( $count, + count($components[$type]), sprintf( 'Expected %1$s %2$s, got %3$s of them', $count, @@ -3114,7 +3171,8 @@ public function testImportNetworkEquipmentMultiConnections() } } } - $this->array($component)->isIdenticalTo($expected); + $this->assertIsArray($component); + $this->assertSame($expected, $component); } //ports connections @@ -3122,14 +3180,14 @@ public function testImportNetworkEquipmentMultiConnections() 'FROM' => \NetworkPort_NetworkPort::getTable(), ]); - $this->integer(count($connections))->isIdenticalTo(63); + $this->assertCount(63, $connections); } $connections = $DB->request(['FROM' => \NetworkPort_NetworkPort::getTable()]); - $this->integer(count($connections))->isIdenticalTo(63); + $this->assertCount(63, $connections); $unmanageds = $DB->request(['FROM' => \Unmanaged::getTable()]); - $this->integer(count($unmanageds))->isIdenticalTo(63); + $this->assertCount(63, $unmanageds); $expecteds = [ [ @@ -3450,12 +3508,12 @@ public function testImportNetworkEquipmentMultiConnections() ] ]; - $this->integer(count($expecteds))->isIdenticalTo($unmanageds->count()); + $this->assertCount($unmanageds->count(), $expecteds); $i = 0; foreach ($unmanageds as $unmanaged) { foreach ($expecteds[$i] as $key => $value) { - $this->variable($unmanaged[$key])->isEqualTo($value); + $this->assertEquals($value, $unmanaged[$key]); } ++$i; } @@ -3463,7 +3521,7 @@ public function testImportNetworkEquipmentMultiConnections() //check matchedlogs $mlogs = new \RuleMatchedLog(); $found = $mlogs->find(); - $this->array($found)->hasSize(61); + $this->assertCount(61, $found); $mrules_criteria = [ 'FROM' => \RuleMatchedLog::getTable(), @@ -3481,17 +3539,17 @@ public function testImportNetworkEquipmentMultiConnections() $neteq_criteria = $mrules_criteria; $neteq_criteria['WHERE'][] = ['itemtype' => \NetworkEquipment::getType()]; $iterator = $DB->request($neteq_criteria); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); foreach ($iterator as $neteq) { - $this->string($neteq['name'])->isIdenticalTo('NetworkEquipment import (by serial)'); - $this->integer($neteq['items_id'])->isIdenticalTo($equipments_id); - $this->string($neteq['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertSame('NetworkEquipment import (by serial)', $neteq['name']); + $this->assertSame($equipments_id, $neteq['items_id']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $neteq['method']); } $unmanaged_criteria = $mrules_criteria; $unmanaged_criteria['WHERE'][] = ['itemtype' => \Unmanaged::getType()]; $iterator = $DB->request($unmanaged_criteria); - $this->integer(count($iterator))->isIdenticalTo(60); + $this->assertCount(60, $iterator); } public function testImportNetworkEquipmentWireless() @@ -3505,42 +3563,40 @@ public function testImportNetworkEquipmentWireless() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(5) - ->string['deviceid']->isIdenticalTo('CH-GV1-DSI-WLC-INSID-1-2020-12-31-11-28-51') - ->string['version']->isIdenticalTo('4.1') - ->string['itemtype']->isIdenticalTo('NetworkEquipment') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('netinventory'); + $this->assertCount(5, $metadata); + $this->assertSame('CH-GV1-DSI-WLC-INSID-1-2020-12-31-11-28-51', $metadata['deviceid']); + $this->assertSame('4.1', $metadata['version']); + $this->assertSame('NetworkEquipment', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('netinventory', $metadata['action']); global $DB; //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); - $this->array($inventory->getAgent()->fields) - ->string['deviceid']->isIdenticalTo('CH-GV1-DSI-WLC-INSID-1-2020-12-31-11-28-51') - ->string['name']->isIdenticalTo('CH-GV1-DSI-WLC-INSID-1-2020-12-31-11-28-51') - //->string['version']->isIdenticalTo('') - ->string['itemtype']->isIdenticalTo('NetworkEquipment') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']); + $this->assertSame('CH-GV1-DSI-WLC-INSID-1-2020-12-31-11-28-51', $inventory->getAgent()->fields['deviceid']); + $this->assertSame('CH-GV1-DSI-WLC-INSID-1-2020-12-31-11-28-51', $inventory->getAgent()->fields['name']); + $this->assertSame('NetworkEquipment', $inventory->getAgent()->fields['itemtype']); + $this->assertSame($agenttype['id'], $inventory->getAgent()->fields['agenttypes_id']); //get model, manufacturer, ... $autoupdatesystems = $DB->request(['FROM' => \AutoupdateSystem::getTable(), 'WHERE' => ['name' => 'GLPI Native Inventory']])->current(); - $this->array($autoupdatesystems); + $this->assertIsArray($autoupdatesystems); $autoupdatesystems_id = $autoupdatesystems['id']; $cmodels = $DB->request(['FROM' => \NetworkEquipmentModel::getTable(), 'WHERE' => ['name' => 'CT5520']])->current(); - $this->array($cmodels); + $this->assertIsArray($cmodels); $models_id = $cmodels['id']; $ctypes = $DB->request(['FROM' => \NetworkEquipmentType::getTable(), 'WHERE' => ['name' => 'Networking']])->current(); - $this->array($ctypes); + $this->assertIsArray($ctypes); $types_id = $ctypes['id']; $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Cisco']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $cloc = $DB->request(['FROM' => \Location::getTable(), 'WHERE' => ['name' => 'MERY']])->current(); - $this->array($cloc); + $this->assertIsArray($cloc); $locations_id = $cloc['id']; //check created equipments @@ -3549,7 +3605,7 @@ public function testImportNetworkEquipmentWireless() 'FROM' => \NetworkEquipment::getTable(), 'WHERE' => ['is_dynamic' => 1] ]); - $this->integer(count($iterator))->isIdenticalTo($expected_eq_count); + $this->assertCount($expected_eq_count, $iterator); $expected_eq = [ 'id' => null, @@ -3593,7 +3649,7 @@ public function testImportNetworkEquipmentWireless() $equipments_id = $row['id']; $expected_eq['id'] = $equipments_id; $equipment = new \NetworkEquipment(); - $this->boolean($equipment->getFromDB($equipments_id))->isTrue(); + $this->assertTrue($equipment->getFromDB($equipments_id)); $expected_eq['date_mod'] = $row['date_mod']; $expected_eq['date_creation'] = $row['date_creation']; if (!$first) { @@ -3604,7 +3660,8 @@ public function testImportNetworkEquipmentWireless() $expected_eq['networkequipmentmodels_id'] = $row['networkequipmentmodels_id']; $expected_eq['manufacturers_id'] = $row['manufacturers_id']; } - $this->array($row)->isIdenticalTo($expected_eq, print_r($row, true) . print_r($expected_eq, true)); + $this->assertIsArray($row); + $this->assertSame($expected_eq, $row, print_r($row, true) . print_r($expected_eq, true)); //check network ports $expected_count = ($first ? 4 : 1); @@ -3615,8 +3672,9 @@ public function testImportNetworkEquipmentWireless() 'itemtype' => 'NetworkEquipment', ], ]); - $this->integer(count($ports_iterator))->isIdenticalTo( + $this->assertSame( $expected_count, + count($ports_iterator), sprintf( '%s ports found on %s, %s expected', count($ports_iterator), @@ -3650,12 +3708,12 @@ public function testImportNetworkEquipmentWireless() foreach ($ports_iterator as $port) { $ports_id = $port['id']; $all_ports_ids[] = $port['id']; - $this->boolean($netport->getFromDB($ports_id))->isTrue(); + $this->assertTrue($netport->getFromDB($ports_id)); $instantiation = $netport->getInstantiation(); if ($port['instantiation_type'] === null) { - $this->boolean($instantiation)->isFalse(); + $this->assertFalse($instantiation); } else { - $this->object($instantiation)->isInstanceOf($port['instantiation_type']); + $this->assertInstanceOf($port['instantiation_type'], $instantiation); } unset($port['id']); @@ -3689,13 +3747,17 @@ public function testImportNetworkEquipmentWireless() 'lastup' => null ]; - $this->array($port)->isEqualTo($expected); + $this->assertIsArray($port); + $this->assertEquals($expected, $port); } else { - $this->string($port['itemtype'])->isIdenticalTo('NetworkEquipment'); - $this->integer($port['items_id'])->isIdenticalTo($equipments_id); - //$this->string($port['instantiation_type'])->isIdenticalTo('NetworkPortAggregate', print_r($port, true)); - $this->string($port['mac'])->matches('/^(?:(?:[0-9a-f]{2}[\:]{1}){5}|(?:[0-9a-f]{2}[-]{1}){5}|(?:[0-9a-f]{2}){5})[0-9a-f]{2}$/i'); - $this->integer($port['is_dynamic'])->isIdenticalTo(1); + $this->assertSame('NetworkEquipment', $port['itemtype']); + $this->assertSame($equipments_id, $port['items_id']); + //$this->assertSame('NetworkPortAggregate', print_r($port, true), $port['instantiation_type']); + $this->assertMatchesRegularExpression( + '/^(?:(?:[0-9a-f]{2}[\:]{1}){5}|(?:[0-9a-f]{2}[-]{1}){5}|(?:[0-9a-f]{2}){5})[0-9a-f]{2}$/i', + $port['mac'] + ); + $this->assertSame(1, $port['is_dynamic']); } ++$i; @@ -3722,10 +3784,11 @@ public function testImportNetworkEquipmentWireless() ] ]); - //$this->integer(count($ip_iterator))->isIdenticalTo(count($ips[$port['name']] ?? ['one' => 'one'])); + //$this->assertCount(count($ips[$port['name']] ?? ['one' => 'one']), $ip_iterator); if ($port['mac'] == '58:ac:78:59:45:fb') { foreach ($ip_iterator as $ip) { - $this->array($ips[$port['name']])->contains($ip['name']); + $this->assertIsArray($ips[$port['name']]); + $this->assertTrue(in_array($ip['name'], $ips[$port['name']])); } } } @@ -3758,8 +3821,9 @@ public function testImportNetworkEquipmentWireless() ]; foreach ($expecteds as $type => $count) { - $this->integer(count($components[$type]))->isIdenticalTo( + $this->assertSame( $count, + count($components[$type]), sprintf( 'Expected %1$s %2$s, got %3$s of them', $count, @@ -3804,17 +3868,18 @@ public function testImportNetworkEquipmentWireless() } } } - $this->array($component)->isIdenticalTo($expected); + $this->assertIsArray($component); + $this->assertSame($expected, $component); } $first = false; } $connections = $DB->request(['FROM' => \NetworkPort_NetworkPort::getTable()]); - $this->integer(count($connections))->isIdenticalTo(2); + $this->assertCount(2, $connections); $unmanageds = $DB->request(['FROM' => \Unmanaged::getTable()]); - $this->integer(count($unmanageds))->isIdenticalTo(2); + $this->assertCount(2, $unmanageds); $expecteds = [ [ @@ -3833,7 +3898,7 @@ public function testImportNetworkEquipmentWireless() $i = 0; foreach ($unmanageds as $unmanaged) { foreach ($expecteds[$i] as $key => $value) { - $this->variable($unmanaged[$key])->isEqualTo($value); + $this->assertEquals($value, $unmanaged[$key]); } ++$i; } @@ -3841,7 +3906,7 @@ public function testImportNetworkEquipmentWireless() //check matchedlogs $mlogs = new \RuleMatchedLog(); $found = $mlogs->find(); - $this->array($found)->hasSize($expected_eq_count + count($unmanageds)); + $this->assertCount($expected_eq_count + count($unmanageds), $found); $mrules_criteria = [ 'FROM' => \RuleMatchedLog::getTable(), @@ -3859,19 +3924,19 @@ public function testImportNetworkEquipmentWireless() $neteq_criteria = $mrules_criteria; $neteq_criteria['WHERE'][] = ['itemtype' => \NetworkEquipment::getType()]; $iterator = $DB->request($neteq_criteria); - $this->integer(count($iterator))->isIdenticalTo($expected_eq_count); + $this->assertCount($expected_eq_count, $iterator); foreach ($iterator as $neteq) { - $this->string($neteq['name'])->isIdenticalTo('NetworkEquipment import (by serial)'); - $this->string($neteq['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertSame('NetworkEquipment import (by serial)', $neteq['name']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $neteq['method']); } $unmanaged_criteria = $mrules_criteria; $unmanaged_criteria['WHERE'][] = ['itemtype' => \Unmanaged::getType()]; $iterator = $DB->request($unmanaged_criteria); - $this->integer(count($iterator))->isIdenticalTo(count($unmanageds)); + $this->assertCount(count($unmanageds), $iterator); foreach ($iterator as $unmanaged) { - $this->string($unmanaged['name'])->isIdenticalTo('Global import (by ip+ifdescr)'); - $this->string($unmanaged['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertSame('Global import (by ip+ifdescr)', $unmanaged['name']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $unmanaged['method']); } } @@ -3886,49 +3951,47 @@ public function testImportNetworkEquipmentWAggregatedPorts() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(5) - ->string['deviceid']->isIdenticalTo('DGS-3420-52T-2020-12-31-11-28-51') - ->string['version']->isIdenticalTo('4.1') - ->string['itemtype']->isIdenticalTo('NetworkEquipment') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('netinventory'); + $this->assertCount(5, $metadata); + $this->assertSame('DGS-3420-52T-2020-12-31-11-28-51', $metadata['deviceid']); + $this->assertSame('4.1', $metadata['version']); + $this->assertSame('NetworkEquipment', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('netinventory', $metadata['action']); global $DB; //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); - $this->array($inventory->getAgent()->fields) - ->string['deviceid']->isIdenticalTo('DGS-3420-52T-2020-12-31-11-28-51') - ->string['name']->isIdenticalTo('DGS-3420-52T-2020-12-31-11-28-51') - //->string['version']->isIdenticalTo('') - ->string['itemtype']->isIdenticalTo('NetworkEquipment') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']); + $this->assertSame('DGS-3420-52T-2020-12-31-11-28-51', $inventory->getAgent()->fields['deviceid']); + $this->assertSame('DGS-3420-52T-2020-12-31-11-28-51', $inventory->getAgent()->fields['name']); + $this->assertSame('NetworkEquipment', $inventory->getAgent()->fields['itemtype']); + $this->assertSame($agenttype['id'], $inventory->getAgent()->fields['agenttypes_id']); //get model, manufacturer, ... $autoupdatesystems = $DB->request(['FROM' => \AutoupdateSystem::getTable(), 'WHERE' => ['name' => 'GLPI Native Inventory']])->current(); - $this->array($autoupdatesystems); + $this->assertIsArray($autoupdatesystems); $autoupdatesystems_id = $autoupdatesystems['id']; $cmodels = $DB->request(['FROM' => \NetworkEquipmentModel::getTable(), 'WHERE' => ['name' => 'DGS-3420-52T']])->current(); - $this->array($cmodels); + $this->assertIsArray($cmodels); $models_id = $cmodels['id']; $ctypes = $DB->request(['FROM' => \NetworkEquipmentType::getTable(), 'WHERE' => ['name' => 'Networking']])->current(); - $this->array($ctypes); + $this->assertIsArray($ctypes); $types_id = $ctypes['id']; $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'D-Link']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; $cloc = $DB->request(['FROM' => \Location::getTable(), 'WHERE' => ['name' => 'WOB Serverraum']])->current(); - $this->array($cloc); + $this->assertIsArray($cloc); $locations_id = $cloc['id']; //check created computer $equipments_id = $inventory->getAgent()->fields['items_id']; - $this->integer($equipments_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $equipments_id); $equipment = new \NetworkEquipment(); - $this->boolean($equipment->getFromDB($equipments_id))->isTrue(); + $this->assertTrue($equipment->getFromDB($equipments_id)); $expected = [ 'id' => $equipments_id, @@ -3966,7 +4029,8 @@ public function testImportNetworkEquipmentWAggregatedPorts() 'last_inventory_update' => $date_now, 'snmpcredentials_id' => 0, ]; - $this->array($equipment->fields)->isIdenticalTo($expected); + $this->assertIsArray($equipment->fields); + $this->assertSame($expected, $equipment->fields); //check network ports $expected_count = 53; @@ -3977,7 +4041,7 @@ public function testImportNetworkEquipmentWAggregatedPorts() 'itemtype' => 'NetworkEquipment', ], ]); - $this->integer(count($iterator))->isIdenticalTo($expected_count); + $this->assertCount($expected_count, $iterator); $expecteds = [ 0 => [ @@ -4014,12 +4078,12 @@ public function testImportNetworkEquipmentWAggregatedPorts() $netport = new \NetworkPort(); foreach ($iterator as $port) { $ports_id = $port['id']; - $this->boolean($netport->getFromDB($ports_id))->isTrue(); + $this->assertTrue($netport->getFromDB($ports_id)); $instantiation = $netport->getInstantiation(); if ($port['instantiation_type'] === null) { - $this->boolean($instantiation)->isFalse(); + $this->assertFalse($instantiation); } else { - $this->object($instantiation)->isInstanceOf($port['instantiation_type']); + $this->assertInstanceOf($port['instantiation_type'], $instantiation); } unset($port['id']); @@ -4053,13 +4117,17 @@ public function testImportNetworkEquipmentWAggregatedPorts() 'lastup' => null ]; - $this->array($port)->isEqualTo($expected); + $this->assertIsArray($port); + $this->assertEquals($expected, $port); } else { - $this->string($port['itemtype'])->isIdenticalTo('NetworkEquipment'); - $this->integer($port['items_id'])->isIdenticalTo($equipments_id); - $this->string($port['instantiation_type'])->isIdenticalTo('NetworkPortEthernet', print_r($port, true)); - $this->string($port['mac'])->matches('/^(?:(?:[0-9a-f]{2}[\:]{1}){5}|(?:[0-9a-f]{2}[-]{1}){5}|(?:[0-9a-f]{2}){5})[0-9a-f]{2}$/i'); - $this->integer($port['is_dynamic'])->isIdenticalTo(1); + $this->assertSame('NetworkEquipment', $port['itemtype']); + $this->assertSame($equipments_id, $port['items_id']); + $this->assertSame('NetworkPortEthernet', $port['instantiation_type'], print_r($port, true)); + $this->assertMatchesRegularExpression( + '/^(?:(?:[0-9a-f]{2}[\:]{1}){5}|(?:[0-9a-f]{2}[-]{1}){5}|(?:[0-9a-f]{2}){5})[0-9a-f]{2}$/i', + $port['mac'] + ); + $this->assertSame(1, $port['is_dynamic']); } ++$i; @@ -4086,10 +4154,11 @@ public function testImportNetworkEquipmentWAggregatedPorts() ] ]); - $this->integer(count($ip_iterator))->isIdenticalTo(count($ips[$port['name']] ?? [])); + $this->assertCount(count($ips[$port['name']] ?? []), $ip_iterator); if (isset($ips[$port['name']])) { foreach ($ip_iterator as $ip) { - $this->array($ips[$port['name']])->contains($ip['name']); + $this->assertIsArray($ips[$port['name']]); + $this->assertTrue(in_array($ip['name'], $ips[$port['name']])); } } } @@ -4122,8 +4191,9 @@ public function testImportNetworkEquipmentWAggregatedPorts() ]; foreach ($expecteds as $type => $count) { - $this->integer(count($components[$type]))->isIdenticalTo( + $this->assertSame( $count, + count($components[$type]), sprintf( 'Expected %1$s %2$s, got %3$s of them', $count, @@ -4168,16 +4238,17 @@ public function testImportNetworkEquipmentWAggregatedPorts() } } } - $this->array($component)->isIdenticalTo($expected); + $this->assertIsArray($component); + $this->assertSame($expected, $component); } //ports connections $connections = $DB->request(['FROM' => \NetworkPort_NetworkPort::getTable()]); - $this->integer(count($connections))->isIdenticalTo(36); + $this->assertCount(36, $connections); //unmanaged equipments $unmanageds = $DB->request(['FROM' => \Unmanaged::getTable()]); - $this->integer(count($unmanageds))->isIdenticalTo(36); + $this->assertCount(36, $unmanageds); } public function testImportRefusedFromAssetRulesWithNoLog() @@ -4185,14 +4256,14 @@ public function testImportRefusedFromAssetRulesWithNoLog() $rule = new \Rule(); //prepares needed rules id - $this->boolean( + $this->assertTrue( $rule->getFromDBByCrit(['name' => 'Computer constraint (name)']) - )->isTrue(); + ); $rules_id_torefuse = $rule->fields['id']; - $this->boolean( + $this->assertTrue( $rule->getFromDBByCrit(['name' => 'Computer import denied']) - )->isTrue(); + ); $rules_id_refuse = $rule->fields['id']; // update action to refused import with no log $action = new \RuleAction(); @@ -4204,66 +4275,65 @@ public function testImportRefusedFromAssetRulesWithNoLog() $action->update($action->fields); - $this->boolean( + $this->assertTrue( $rule->getFromDBByCrit(['name' => 'Computer import (by name)']) - )->isTrue(); + ); $rules_id_toaccept = $rule->fields['id']; //move rule to refuse computer inventory $rulecollection = new \RuleImportAssetCollection(); - $this->boolean( + $this->assertTrue( $rulecollection->moveRule( $rules_id_refuse, $rules_id_torefuse, \RuleCollection::MOVE_BEFORE ) - )->isTrue(); + ); //do inventory $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_1.json')); $inventory = $this->doInventory($json); //move rule back to accept computer inventory - $this->boolean( + $this->assertTrue( $rulecollection->moveRule( $rules_id_refuse, $rules_id_toaccept, \RuleCollection::MOVE_AFTER ) - )->isTrue(); + ); //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(7) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['version']->isIdenticalTo('FusionInventory-Agent_v2.5.2-1.fc31') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['tag']->isIdenticalTo('000005') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('inventory'); - $this->array($metadata['provider'])->hasSize(10); + $this->assertCount(7, $metadata); + $this->assertSame('glpixps-2018-07-09-09-07-13', $metadata['deviceid']); + $this->assertSame('FusionInventory-Agent_v2.5.2-1.fc31', $metadata['version']); + $this->assertSame('Computer', $metadata['itemtype']); + $this->assertSame('000005', $metadata['tag']); + $this->assertNull($metadata['port']); + $this->assertSame('inventory', $metadata['action']); + $this->assertCount(10, $metadata['provider']); global $DB; //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['name']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['version']->isIdenticalTo('2.5.2-1.fc31') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['tag']->isIdenticalTo('000005') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['deviceid']); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['name']); + $this->assertSame('2.5.2-1.fc31', $agent['version']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame('000005', $agent['tag']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); $computers_id = $agent['items_id']; - $this->integer($computers_id)->isIdenticalTo(0); + $this->assertSame(0, $computers_id); $iterator = $DB->request([ 'FROM' => \RefusedEquipment::getTable(), ]); - $this->integer(count($iterator))->isIdenticalTo(0); + $this->assertCount(0, $iterator); } public function testImportRefusedFromAssetRulesWithLog() @@ -4271,89 +4341,88 @@ public function testImportRefusedFromAssetRulesWithLog() $rule = new \Rule(); //prepares needed rules id - $this->boolean( + $this->assertTrue( $rule->getFromDBByCrit(['name' => 'Computer constraint (name)']) - )->isTrue(); + ); $rules_id_torefuse = $rule->fields['id']; - $this->boolean( + $this->assertTrue( $rule->getFromDBByCrit(['name' => 'Computer import denied']) - )->isTrue(); + ); $rules_id_refuse = $rule->fields['id']; //update ruleAction to refused import with log $ruleaction = new \RuleAction(); - $this->boolean($ruleaction->getFromDBByCrit(['rules_id' => $rules_id_refuse]))->isTrue(); - $this->boolean( + $this->assertTrue($ruleaction->getFromDBByCrit(['rules_id' => $rules_id_refuse])); + $this->assertTrue( $ruleaction->update([ 'id' => $ruleaction->fields['id'], 'field' => '_ignore_import', 'action_type' => 'assign', 'value' => 1 ]) - )->isTrue(); + ); - $this->boolean( + $this->assertTrue( $rule->getFromDBByCrit(['name' => 'Computer import (by name)']) - )->isTrue(); + ); $rules_id_toaccept = $rule->fields['id']; //move rule to refuse computer inventory $rulecollection = new \RuleImportAssetCollection(); - $this->boolean( + $this->assertTrue( $rulecollection->moveRule( $rules_id_refuse, $rules_id_torefuse, \RuleCollection::MOVE_BEFORE ) - )->isTrue(); + ); //do inventory $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_1.json')); $inventory = $this->doInventory($json); //move rule back to accept computer inventory - $this->boolean( + $this->assertTrue( $rulecollection->moveRule( $rules_id_refuse, $rules_id_toaccept, \RuleCollection::MOVE_AFTER ) - )->isTrue(); + ); //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(7) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['version']->isIdenticalTo('FusionInventory-Agent_v2.5.2-1.fc31') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['tag']->isIdenticalTo('000005') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('inventory'); - $this->array($metadata['provider'])->hasSize(10); + $this->assertCount(7, $metadata); + $this->assertSame('glpixps-2018-07-09-09-07-13', $metadata['deviceid']); + $this->assertSame('FusionInventory-Agent_v2.5.2-1.fc31', $metadata['version']); + $this->assertSame('Computer', $metadata['itemtype']); + $this->assertSame('000005', $metadata['tag']); + $this->assertNull($metadata['port']); + $this->assertSame('inventory', $metadata['action']); + $this->assertCount(10, $metadata['provider']); global $DB; //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['name']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['version']->isIdenticalTo('2.5.2-1.fc31') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['tag']->isIdenticalTo('000005') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['deviceid']); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['name']); + $this->assertSame('2.5.2-1.fc31', $agent['version']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame('000005', $agent['tag']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); $computers_id = $agent['items_id']; - $this->integer($computers_id)->isIdenticalTo(0); + $this->assertSame(0, $computers_id); $iterator = $DB->request([ 'FROM' => \RefusedEquipment::getTable(), ]); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); $result = $iterator->current(); $expected = [ @@ -4373,16 +4442,17 @@ public function testImportRefusedFromAssetRulesWithLog() 'autoupdatesystems_id' => $result['autoupdatesystems_id'] ]; - $this->array($result)->isEqualTo($expected); + $this->assertIsArray($result); + $this->assertEquals($expected, $result); //check no matchedlogs $mlogs = new \RuleMatchedLog(); $found = $mlogs->find(); - $this->array($found)->hasSize(0); + $this->assertCount(0, $found); //test inventory from refused equipment, will be accepted since rules has been reset ;) $refused = new \RefusedEquipment(); - $this->boolean($refused->getFromDB($result['id']))->isTrue(); + $this->assertTrue($refused->getFromDB($result['id'])); $inventory_request = new \Glpi\Inventory\Request(); $inventory_request->handleContentType('application/json'); @@ -4401,20 +4471,20 @@ public function testImportRefusedFromAssetRulesWithLog() $iterator = $DB->request([ 'FROM' => \RefusedEquipment::getTable(), ]); - $this->integer(count($iterator))->isIdenticalTo(0); + $this->assertCount(0, $iterator); //but a linked computer $gagent = new \Agent(); - $this->boolean($gagent->getFromDB($agent['id']))->isTrue(); + $this->assertTrue($gagent->getFromDB($agent['id'])); $computer = new \Computer(); - $this->boolean($computer->getFromDB($gagent->fields['items_id']))->isTrue(); - $this->string($computer->fields['name'])->isIdenticalTo('glpixps'); + $this->assertTrue($computer->getFromDB($gagent->fields['items_id'])); + $this->assertSame('glpixps', $computer->fields['name']); //check no matchedlogs $mlogs = new \RuleMatchedLog(); $found = $mlogs->find(); - $this->array($found)->hasSize(3); + $this->assertCount(3, $found); $criteria = [ 'FROM' => \RuleMatchedLog::getTable(), @@ -4432,24 +4502,24 @@ public function testImportRefusedFromAssetRulesWithLog() $monitor_criteria = $criteria; $monitor_criteria['WHERE'] = ['itemtype' => \Monitor::getType()]; $iterator = $DB->request($monitor_criteria); - $this->integer(count($iterator))->isIdenticalTo(1); - $this->string($iterator->current()['name'])->isIdenticalTo('Monitor import (by serial)'); - $this->string($iterator->current()['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertCount(1, $iterator); + $this->assertSame('Monitor import (by serial)', $iterator->current()['name']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $iterator->current()['method']); $printer_criteria = $criteria; $printer_criteria['WHERE'] = ['itemtype' => \Printer::getType()]; $iterator = $DB->request($printer_criteria); - $this->integer(count($iterator))->isIdenticalTo(1); - $this->string($iterator->current()['name'])->isIdenticalTo('Printer import (by serial)'); - $this->string($iterator->current()['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertCount(1, $iterator); + $this->assertSame('Printer import (by serial)', $iterator->current()['name']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $iterator->current()['method']); $computer_criteria = $criteria; $computer_criteria['WHERE'] = ['itemtype' => \Computer::getType()]; $iterator = $DB->request($computer_criteria); - $this->integer(count($iterator))->isIdenticalTo(1); - $this->string($iterator->current()['name'])->isIdenticalTo('Computer import (by serial + uuid)'); - $this->integer($iterator->current()['items_id'])->isIdenticalTo($gagent->fields['items_id']); - $this->string($iterator->current()['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertCount(1, $iterator); + $this->assertSame('Computer import (by serial + uuid)', $iterator->current()['name']); + $this->assertSame($gagent->fields['items_id'], $iterator->current()['items_id']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $iterator->current()['method']); } public function testImportRefusedFromEntitiesRules() @@ -4465,29 +4535,31 @@ public function testImportRefusedFromEntitiesRules() 'ranking' => 1 ]; $rules_id = $rule->add($input); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); // Add criteria $rulecriteria = new \RuleCriteria(); - $this->integer( + $this->assertGreaterThan( + 0, $rulecriteria->add([ 'rules_id' => $rules_id, 'criteria' => "deviceid", 'pattern' => "/^glpixps.*/", 'condition' => \RuleImportEntity::REGEX_MATCH ]) - )->isGreaterThan(0); + ); // Add action $ruleaction = new \RuleAction(); - $this->integer( + $this->assertGreaterThan( + 0, $ruleaction->add([ 'rules_id' => $rules_id, 'action_type' => 'assign', 'field' => '_ignore_import', 'value' => 1 ]) - )->isGreaterThan(0); + ); $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_1.json')); unset($json->content->bios); @@ -4496,36 +4568,35 @@ public function testImportRefusedFromEntitiesRules() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(7) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['version']->isIdenticalTo('FusionInventory-Agent_v2.5.2-1.fc31') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['tag']->isIdenticalTo('000005') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('inventory'); - $this->array($metadata['provider'])->hasSize(10); + $this->assertCount(7, $metadata); + $this->assertSame('glpixps-2018-07-09-09-07-13', $metadata['deviceid']); + $this->assertSame('FusionInventory-Agent_v2.5.2-1.fc31', $metadata['version']); + $this->assertSame('Computer', $metadata['itemtype']); + $this->assertSame('000005', $metadata['tag']); + $this->assertNull($metadata['port']); + $this->assertSame('inventory', $metadata['action']); + $this->assertCount(10, $metadata['provider']); global $DB; //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['name']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['version']->isIdenticalTo('2.5.2-1.fc31') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['tag']->isIdenticalTo('000005') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['deviceid']); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['name']); + $this->assertSame('2.5.2-1.fc31', $agent['version']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame('000005', $agent['tag']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); $computers_id = $agent['items_id']; - $this->integer($computers_id)->isIdenticalTo(0); + $this->assertSame(0, $computers_id); $iterator = $DB->request([ 'FROM' => \RefusedEquipment::getTable(), ]); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); $result = $iterator->current(); $expected = [ @@ -4545,7 +4616,8 @@ public function testImportRefusedFromEntitiesRules() 'autoupdatesystems_id' => $result['autoupdatesystems_id'] ]; - $this->array($result)->isEqualTo($expected); + $this->assertIsArray($result); + $this->assertEquals($expected, $result); } public function testImportFiles() @@ -4557,21 +4629,17 @@ public function testImportFiles() $json_path = self::INV_FIXTURES . $json_name; $conf = new \Glpi\Inventory\Conf(); $result = $conf->importFiles([$json_name => $json_path]); - $this - ->array($result[$json_name]) - ->then - ->boolean($result[$json_name]['success']) - ->isTrue() - ->then - ->object($result[$json_name]['items'][0]) - ->isInstanceOf('Computer'); + + $this->assertIsArray($result[$json_name]); + $this->assertTrue($result[$json_name]['success']); + $this->assertInstanceOf('Computer', $result[$json_name]['items'][0]); //1 computer and 1 printer has been inventoried $nbcomputers++; $nbprinters++; - $this->integer($nbcomputers)->isIdenticalTo(countElementsInTable(\Computer::getTable())); - $this->integer($nbprinters)->isIdenticalTo(countElementsInTable(\Printer::getTable())); + $this->assertSame(countElementsInTable(\Computer::getTable()), $nbcomputers); + $this->assertSame(countElementsInTable(\Printer::getTable()), $nbprinters); } /** @@ -4594,40 +4662,28 @@ public function testArchive() $conf = new \Glpi\Inventory\Conf(); $result = $conf->importFiles(['to_inventory.zip' => self::INVENTORY_ARCHIVE_PATH]); - $this->array($result)->hasSize(3); + $this->assertCount(3, $result); // Expected result for computer_1.json - $this - ->boolean($result['to_inventory.zip/computer_1.json']['success']) - ->isTrue() - ->then - ->object($result['to_inventory.zip/computer_1.json']['items'][0]) - ->isInstanceOf('Computer'); + $this->assertTrue($result['to_inventory.zip/computer_1.json']['success']); + $this->assertInstanceOf('Computer', $result['to_inventory.zip/computer_1.json']['items'][0]); // Expected result for networkequipment_1.json - $this - ->boolean($result['to_inventory.zip/networkequipment_1.json']['success']) - ->isTrue() - ->then - ->object($result['to_inventory.zip/networkequipment_1.json']['items'][0]) - ->isInstanceOf('NetworkEquipment'); + $this->assertTrue($result['to_inventory.zip/networkequipment_1.json']['success']); + $this->assertInstanceOf('NetworkEquipment', $result['to_inventory.zip/networkequipment_1.json']['items'][0]); // Expected result for printer_1.json - $this - ->boolean($result['to_inventory.zip/printer_1.json']['success']) - ->isTrue() - ->then - ->object($result['to_inventory.zip/printer_1.json']['items'][0]) - ->isInstanceOf('Printer'); + $this->assertTrue($result['to_inventory.zip/printer_1.json']['success']); + $this->assertInstanceOf('Printer', $result['to_inventory.zip/printer_1.json']['items'][0]); //1 computer 2 printers and a network equipment has been inventoried $nbcomputers++; $nbprinters += 2; $nbnetequps++; - $this->integer($nbcomputers)->isIdenticalTo(countElementsInTable(\Computer::getTable())); - $this->integer($nbprinters)->isIdenticalTo(countElementsInTable(\Printer::getTable())); - $this->integer($nbnetequps)->isIdenticalTo(countElementsInTable(\NetworkEquipment::getTable())); + $this->assertSame(countElementsInTable(\Computer::getTable()), $nbcomputers); + $this->assertSame(countElementsInTable(\Printer::getTable()), $nbprinters); + $this->assertSame(countElementsInTable(\NetworkEquipment::getTable()), $nbnetequps); } public function testImportVirtualMachines() @@ -4637,7 +4693,7 @@ public function testImportVirtualMachines() $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_2.json')); $count_vms = count($json->content->virtualmachines); - $this->integer($count_vms)->isIdenticalTo(6); + $this->assertSame(6, $count_vms); $nb_vms = countElementsInTable(\ComputerVirtualMachine::getTable()); $nb_computers = countElementsInTable(\Computer::getTable()); @@ -4645,23 +4701,23 @@ public function testImportVirtualMachines() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(5) - ->string['deviceid']->isIdenticalTo('acomputer-2021-01-26-14-32-36') - ->string['itemtype']->isIdenticalTo('Computer') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('inventory'); + $this->assertCount(5, $metadata); + $this->assertSame('acomputer-2021-01-26-14-32-36', $metadata['deviceid']); + $this->assertSame('Computer', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('inventory', $metadata['action']); //check we add only one computer ++$nb_computers; - $this->integer(countElementsInTable(\Computer::getTable()))->isIdenticalTo($nb_computers); + $this->assertSame($nb_computers, countElementsInTable(\Computer::getTable())); //check created vms $nb_vms += $count_vms; - $this->integer(countElementsInTable(\ComputerVirtualMachine::getTable()))->isIdenticalTo($nb_vms); + $this->assertSame($nb_vms, countElementsInTable(\ComputerVirtualMachine::getTable())); //change config to import vms as computers $this->login(); $conf = new \Glpi\Inventory\Conf(); - $this->boolean($conf->saveConf(['vm_as_computer' => 1]))->isTrue(); + $this->assertTrue($conf->saveConf(['vm_as_computer' => 1])); $this->logout(); $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_2.json')); @@ -4669,25 +4725,25 @@ public function testImportVirtualMachines() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(5) - ->string['deviceid']->isIdenticalTo('acomputer-2021-01-26-14-32-36') - ->string['itemtype']->isIdenticalTo('Computer') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('inventory'); + $this->assertCount(5, $metadata); + $this->assertSame('acomputer-2021-01-26-14-32-36', $metadata['deviceid']); + $this->assertSame('Computer', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('inventory', $metadata['action']); //check we add main computer and one computer per vm //one does not have an uuid, so no computer is created. - $this->integer(countElementsInTable(\Computer::getTable()))->isIdenticalTo($nb_computers + $count_vms - 1); + $this->assertSame($nb_computers + $count_vms - 1, countElementsInTable(\Computer::getTable())); //check created vms - $this->integer(countElementsInTable(\ComputerVirtualMachine::getTable()))->isIdenticalTo($nb_vms); + $this->assertSame($nb_vms, countElementsInTable(\ComputerVirtualMachine::getTable())); //partial inventory: postgres vm has been stopped $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_2_partial_vms.json')); $this->doInventory($json); //check nothing has changed - $this->integer(countElementsInTable(\Computer::getTable()))->isIdenticalTo($nb_computers + $count_vms - 1); - $this->integer(countElementsInTable(\ComputerVirtualMachine::getTable()))->isIdenticalTo($nb_vms); + $this->assertSame($nb_computers + $count_vms - 1, countElementsInTable(\Computer::getTable())); + $this->assertSame($nb_vms, countElementsInTable(\ComputerVirtualMachine::getTable())); $iterator = $DB->request([ 'SELECT' => [ @@ -4709,7 +4765,7 @@ public function testImportVirtualMachines() \VirtualMachineState::getTable() . '.name' => 'off' ] ]); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); } public function testUpdateVirtualMachines() @@ -4719,7 +4775,7 @@ public function testUpdateVirtualMachines() $json = json_decode(file_get_contents(GLPI_ROOT . '/tests/fixtures/inventories/lxc-server-1.json')); $count_vms = count($json->content->virtualmachines); - $this->integer($count_vms)->isIdenticalTo(1); + $this->assertSame(1, $count_vms); $nb_vms = countElementsInTable(\ComputerVirtualMachine::getTable()); $nb_computers = countElementsInTable(\Computer::getTable()); @@ -4727,40 +4783,37 @@ public function testUpdateVirtualMachines() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(5) - ->string['deviceid']->isIdenticalTo('lxc-server-2022-08-09-17-49-51') - ->string['itemtype']->isIdenticalTo('Computer') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('inventory'); + $this->assertCount(5, $metadata); + $this->assertSame('lxc-server-2022-08-09-17-49-51', $metadata['deviceid']); + $this->assertSame('Computer', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('inventory', $metadata['action']); //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('lxc-server-2022-08-09-17-49-51') - ->string['name']->isIdenticalTo('lxc-server-2022-08-09-17-49-51') - ->string['itemtype']->isIdenticalTo('Computer') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']); + $this->assertSame('lxc-server-2022-08-09-17-49-51', $agent['deviceid']); + $this->assertSame('lxc-server-2022-08-09-17-49-51', $agent['name']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); $computers_id = $agent['items_id']; //check we add only one computer ++$nb_computers; - $this->integer(countElementsInTable(\Computer::getTable()))->isIdenticalTo($nb_computers); + $this->assertSame($nb_computers, countElementsInTable(\Computer::getTable())); //check created vms $nb_vms += $count_vms; - $this->integer(countElementsInTable(\ComputerVirtualMachine::getTable()))->isIdenticalTo($nb_vms); + $this->assertSame($nb_vms, countElementsInTable(\ComputerVirtualMachine::getTable())); $cvms = new \ComputerVirtualMachine(); - $this->boolean($cvms->getFromDBByCrit(['computers_id' => $computers_id]))->isTrue(); + $this->assertTrue($cvms->getFromDBByCrit(['computers_id' => $computers_id])); - $this->array($cvms->fields) - ->string['name']->isIdenticalTo('glpi-10-rc1') - ->integer['vcpu']->isIdenticalTo(2) - ->integer['ram']->isIdenticalTo(2048) - ->string['uuid']->isIdenticalTo('487dfdb542a4bfb23670b8d4e76d8b6886c2ed35') - ; + $this->assertSame('glpi-10-rc1', $cvms->fields['name']); + $this->assertSame(2, $cvms->fields['vcpu']); + $this->assertSame(2048, $cvms->fields['ram']); + $this->assertSame('487dfdb542a4bfb23670b8d4e76d8b6886c2ed35', $cvms->fields['uuid']); //import again, RAM has changed $json = json_decode(file_get_contents(GLPI_ROOT . '/tests/fixtures/inventories/lxc-server-1.json')); @@ -4771,14 +4824,12 @@ public function testUpdateVirtualMachines() $this->doInventory($json); - $this->boolean($cvms->getFromDBByCrit(['computers_id' => $computers_id]))->isTrue(); + $this->assertTrue($cvms->getFromDBByCrit(['computers_id' => $computers_id])); - $this->array($cvms->fields) - ->string['name']->isIdenticalTo('glpi-10-rc1') - ->integer['vcpu']->isIdenticalTo(2) - ->integer['ram']->isIdenticalTo(4096) - ->string['uuid']->isIdenticalTo('487dfdb542a4bfb23670b8d4e76d8b6886c2ed35') - ; + $this->assertSame('glpi-10-rc1', $cvms->fields['name']); + $this->assertSame(2, $cvms->fields['vcpu']); + $this->assertSame(4096, $cvms->fields['ram']); + $this->assertSame('487dfdb542a4bfb23670b8d4e76d8b6886c2ed35', $cvms->fields['uuid']); } public function testRuleRefuseImportVirtualMachines() @@ -4786,7 +4837,7 @@ public function testRuleRefuseImportVirtualMachines() $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_2.json')); $count_vms = count($json->content->virtualmachines); - $this->integer($count_vms)->isIdenticalTo(6); + $this->assertSame(6, $count_vms); $nb_vms = countElementsInTable(\ComputerVirtualMachine::getTable()); $nb_computers = countElementsInTable(\Computer::getTable()); @@ -4794,7 +4845,7 @@ public function testRuleRefuseImportVirtualMachines() //change config to import vms as computers $this->login(); $conf = new \Glpi\Inventory\Conf(); - $this->boolean($conf->saveConf(['vm_as_computer' => 1]))->isTrue(); + $this->assertTrue($conf->saveConf(['vm_as_computer' => 1])); $this->logout(); //IMPORT rule to refuse "db" virtual machine @@ -4826,8 +4877,8 @@ public function testRuleRefuseImportVirtualMachines() ]; $rules_id = $rule->add($input); - $this->integer($rules_id)->isGreaterThan(0); - $this->boolean($collection->moveRule($rules_id, 0, $collection::MOVE_BEFORE))->isTrue(); + $this->assertGreaterThan(0, $rules_id); + $this->assertTrue($collection->moveRule($rules_id, 0, $collection::MOVE_BEFORE)); // Add criteria foreach ($criteria as $crit) { @@ -4837,7 +4888,7 @@ public function testRuleRefuseImportVirtualMachines() 'pattern' => $crit['pattern'], 'condition' => $crit['condition'], ]; - $this->integer((int)$rulecriteria->add($input))->isGreaterThan(0); + $this->assertGreaterThan(0, (int)$rulecriteria->add($input)); } // Add action @@ -4848,28 +4899,26 @@ public function testRuleRefuseImportVirtualMachines() 'field' => $action['field'], 'value' => $action['value'], ]; - $this->integer((int)$ruleaction->add($input))->isGreaterThan(0); + $this->assertGreaterThan(0, (int)$ruleaction->add($input)); $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_2.json')); $inventory = $this->doInventory($json); //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(5) - ->string['deviceid']->isIdenticalTo('acomputer-2021-01-26-14-32-36') - ->string['itemtype']->isIdenticalTo('Computer') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('inventory'); - - global $DB; + $this->assertCount(5, $metadata); + $this->assertSame('acomputer-2021-01-26-14-32-36', $metadata['deviceid']); + $this->assertSame('Computer', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('inventory', $metadata['action']); //check created vms - $this->integer(countElementsInTable(\ComputerVirtualMachine::getTable()))->isIdenticalTo($count_vms); + $this->assertSame($count_vms, countElementsInTable(\ComputerVirtualMachine::getTable())); //check we add main computer and one computer per vm //one does not have an uuid, so no computer is created. ++$nb_computers; - $this->integer(countElementsInTable(\Computer::getTable()))->isIdenticalTo($nb_computers + $count_vms - 2); + $this->assertSame($nb_computers + $count_vms - 2, countElementsInTable(\Computer::getTable())); } public function testImportDatabases() @@ -4881,11 +4930,11 @@ public function testImportDatabases() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(5) - ->string['deviceid']->isIdenticalTo('acomputer-2021-01-26-14-32-36') - ->string['itemtype']->isIdenticalTo('Computer') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('inventory'); + $this->assertCount(5, $metadata); + $this->assertSame('acomputer-2021-01-26-14-32-36', $metadata['deviceid']); + $this->assertSame('Computer', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('inventory', $metadata['action']); //partial inventory: add databases @@ -4918,8 +4967,8 @@ public function testImportDatabases() ]; $rules_id = $rule->add($input); - $this->integer($rules_id)->isGreaterThan(0); - $this->boolean($collection->moveRule($rules_id, 0, $collection::MOVE_BEFORE))->isTrue(); + $this->assertGreaterThan(0, $rules_id); + $this->assertTrue($collection->moveRule($rules_id, 0, $collection::MOVE_BEFORE)); // Add criteria foreach ($criteria as $crit) { @@ -4929,7 +4978,7 @@ public function testImportDatabases() 'pattern' => $crit['pattern'], 'condition' => $crit['condition'], ]; - $this->integer((int)$rulecriteria->add($input))->isGreaterThan(0); + $this->assertGreaterThan(0, (int)$rulecriteria->add($input)); } // Add action @@ -4940,7 +4989,7 @@ public function testImportDatabases() 'field' => $action['field'], 'value' => $action['value'], ]; - $this->integer((int)$ruleaction->add($input))->isGreaterThan(0); + $this->assertGreaterThan(0, (int)$ruleaction->add($input)); //UPDATE rule $criteria = [ @@ -4976,8 +5025,8 @@ public function testImportDatabases() $prev_rules_id = $rules_id; $rules_id = $rule->add($input); - $this->integer($rules_id)->isGreaterThan(0); - $this->boolean($collection->moveRule($rules_id, $prev_rules_id, $collection::MOVE_BEFORE))->isTrue(); + $this->assertGreaterThan(0, $rules_id); + $this->assertTrue($collection->moveRule($rules_id, $prev_rules_id, $collection::MOVE_BEFORE)); // Add criteria foreach ($criteria as $crit) { @@ -4987,7 +5036,7 @@ public function testImportDatabases() 'pattern' => $crit['pattern'], 'condition' => $crit['condition'], ]; - $this->integer((int)$rulecriteria->add($input))->isGreaterThan(0); + $this->assertGreaterThan(0, (int)$rulecriteria->add($input)); } // Add action @@ -4998,29 +5047,29 @@ public function testImportDatabases() 'field' => $action['field'], 'value' => $action['value'], ]; - $this->integer((int)$ruleaction->add($input))->isGreaterThan(0); + $this->assertGreaterThan(0, (int)$ruleaction->add($input)); $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_2_partial_dbs.json')); $this->doInventory($json); //check nothing has changed - $this->integer(countElementsInTable(\Computer::getTable()))->isIdenticalTo($nb_computers + 1); + $this->assertSame($nb_computers + 1, countElementsInTable(\Computer::getTable())); //check created databases & instances - $this->integer(countElementsInTable(\DatabaseInstance::getTable()))->isIdenticalTo(2); - $this->integer(countElementsInTable(\DatabaseInstance::getTable(), ['is_dynamic' => 1]))->isIdenticalTo(2); - $this->integer(countElementsInTable(\Database::getTable()))->isIdenticalTo(3); + $this->assertSame(2, countElementsInTable(\DatabaseInstance::getTable())); + $this->assertSame(2, countElementsInTable(\DatabaseInstance::getTable(), ['is_dynamic' => 1])); + $this->assertSame(3, countElementsInTable(\Database::getTable())); //play an update - nothing should have changed $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_2_partial_dbs.json')); $this->doInventory($json); //check nothing has changed - $this->integer(countElementsInTable(\Computer::getTable()))->isIdenticalTo($nb_computers + 1); + $this->assertSame($nb_computers + 1, countElementsInTable(\Computer::getTable())); //check created databases & instances - $this->integer(countElementsInTable(\DatabaseInstance::getTable()))->isIdenticalTo(2); - $this->integer(countElementsInTable(\Database::getTable()))->isIdenticalTo(3); + $this->assertSame(2, countElementsInTable(\DatabaseInstance::getTable())); + $this->assertSame(3, countElementsInTable(\Database::getTable())); //keep only mysql $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_2_partial_dbs.json')); @@ -5043,23 +5092,26 @@ public function testImportDatabases() $this->doInventory($json); //check created databases & instances - $this->integer(countElementsInTable(\DatabaseInstance::getTable(), ['is_deleted' => 0]))->isIdenticalTo(1); - $this->integer(countElementsInTable(\DatabaseInstance::getTable(), ['is_deleted' => 1]))->isIdenticalTo(1); + $this->assertSame(1, countElementsInTable(\DatabaseInstance::getTable(), ['is_deleted' => 0])); + $this->assertSame(1, countElementsInTable(\DatabaseInstance::getTable(), ['is_deleted' => 1])); //ensure database version has been updated $database = new \DatabaseInstance(); - $this->boolean($database->getFromDBByCrit(['name' => 'MariaDB']))->isTrue(); - $this->string($database->fields['version'])->isIdenticalTo('Ver 15.1 Distrib 10.5.10-MariaDB-modified'); + $this->assertTrue($database->getFromDBByCrit(['name' => 'MariaDB'])); + $this->assertSame('Ver 15.1 Distrib 10.5.10-MariaDB-modified', $database->fields['version']); //- ensure existing instances has been updated $databases = $database->getDatabases(); - $this->array($databases)->hasSize(2); - $this->array(array_pop($databases)) - ->string['name']->isIdenticalTo('new_database') - ->integer['size']->isIdenticalTo(2048); - $this->array(array_pop($databases)) - ->string['name']->isIdenticalTo('glpi') - ->integer['size']->isIdenticalTo(55000); + $this->assertCount(2, $databases); + + $database = array_pop($databases); + $this->assertIsArray($database); + $this->assertSame('new_database', $database['name']); + $this->assertSame(2048, $database['size']); + $database = array_pop($databases); + $this->assertIsArray($database); + $this->assertSame('glpi', $database['name']); + $this->assertSame(55000, $database['size']); //test sql syntax error $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_2_partial_dbs.json')); @@ -5082,23 +5134,25 @@ public function testImportDatabases() $this->doInventory($json); //check created databases & instances - $this->integer(countElementsInTable(\DatabaseInstance::getTable(), ['is_deleted' => 0]))->isIdenticalTo(1); - $this->integer(countElementsInTable(\DatabaseInstance::getTable(), ['is_deleted' => 1]))->isIdenticalTo(2); + $this->assertSame(1, countElementsInTable(\DatabaseInstance::getTable(), ['is_deleted' => 0])); + $this->assertSame(2, countElementsInTable(\DatabaseInstance::getTable(), ['is_deleted' => 1])); //ensure database version has been updated $database = new \DatabaseInstance(); - $this->boolean($database->getFromDBByCrit(['name' => 'MariaDB']))->isTrue(); - $this->string($database->fields['version'])->isIdenticalTo('Ver 15.1 Distrib 10.5.10-MariaDB-modified'); + $this->assertTrue($database->getFromDBByCrit(['name' => 'MariaDB'])); + $this->assertSame('Ver 15.1 Distrib 10.5.10-MariaDB-modified', $database->fields['version']); //- ensure existing instances has been updated $databases = $database->getDatabases(); - $this->array($databases)->hasSize(2); - $this->array(array_pop($databases)) - ->string['name']->isIdenticalTo('new_database') - ->integer['size']->isIdenticalTo(2048); - $this->array(array_pop($databases)) - ->string['name']->isIdenticalTo('glpi') - ->integer['size']->isIdenticalTo(55000); + $this->assertCount(2, $databases); + $database = array_pop($databases); + $this->assertIsArray($database); + $this->assertSame('new_database', $database['name']); + $this->assertSame(2048, $database['size']); + $database = array_pop($databases); + $this->assertIsArray($database); + $this->assertSame('glpi', $database['name']); + $this->assertSame(55000, $database['size']); } @@ -5133,18 +5187,18 @@ public function testImportPhoneSimCardNoReset() $this->doInventory($xml, true); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check created computer $phone = new \Phone(); - $this->boolean($phone->getFromDB($agent['items_id']))->isTrue(); + $this->assertTrue($phone->getFromDB($agent['items_id'])); //check for components $item_devicesimcard = new \Item_DeviceSimcard(); $simcards_first = $item_devicesimcard->find(['itemtype' => 'Phone' , 'items_id' => $agent['items_id']]); - $this->integer(count($simcards_first))->isIdenticalTo(1); + $this->assertCount(1, $simcards_first); //re run inventory to check if item_simcard ID is changed $json = json_decode(file_get_contents(self::INV_FIXTURES . 'phone_1.json')); @@ -5152,9 +5206,10 @@ public function testImportPhoneSimCardNoReset() $this->doInventory($json); $item_devicesimcard = new \Item_DeviceSimcard(); $simcards_second = $item_devicesimcard->find(['itemtype' => 'Phone' , 'items_id' => $agent['items_id']]); - $this->integer(count($simcards_second))->isIdenticalTo(1); + $this->assertCount(1, $simcards_second); - $this->array($simcards_first)->isIdenticalTo($simcards_second); + $this->assertIsArray($simcards_first); + $this->assertSame($simcards_second, $simcards_first); } public function testImportPhoneMultiSimCardNoReset() @@ -5197,18 +5252,18 @@ public function testImportPhoneMultiSimCardNoReset() $this->doInventory($xml, true); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check created computer $phone = new \Phone(); - $this->boolean($phone->getFromDB($agent['items_id']))->isTrue(); + $this->assertTrue($phone->getFromDB($agent['items_id'])); //check for components $item_devicesimcard = new \Item_DeviceSimcard(); $simcards_first = $item_devicesimcard->find(['itemtype' => 'Phone' , 'items_id' => $agent['items_id']]); - $this->integer(count($simcards_first))->isIdenticalTo(2); + $this->assertCount(2, $simcards_first); //re run inventory to check if item_simcard ID is changed $json = json_decode(file_get_contents(self::INV_FIXTURES . 'phone_1.json')); @@ -5216,9 +5271,10 @@ public function testImportPhoneMultiSimCardNoReset() $this->doInventory($json); $item_devicesimcard = new \Item_DeviceSimcard(); $simcards_second = $item_devicesimcard->find(['itemtype' => 'Phone' , 'items_id' => $agent['items_id']]); - $this->integer(count($simcards_second))->isIdenticalTo(2); + $this->assertCount(2, $simcards_second); - $this->array($simcards_first)->isIdenticalTo($simcards_second); + $this->assertIsArray($simcards_first); + $this->assertSame($simcards_second, $simcards_first); } @@ -5232,29 +5288,29 @@ public function testImportPhone() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(5) - ->string['deviceid']->isIdenticalTo('Mi9TPro-TéléphoneM-2019-12-18-14-30-16') - ->string['version']->isIdenticalTo('example-app-java') - ->string['itemtype']->isIdenticalTo('Phone') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('inventory'); + $this->assertCount(5, $metadata); + $this->assertSame('Mi9TPro-TéléphoneM-2019-12-18-14-30-16', $metadata['deviceid']); + $this->assertSame('example-app-java', $metadata['version']); + $this->assertSame('Phone', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('inventory', $metadata['action']); //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('Mi9TPro-TéléphoneM-2019-12-18-14-30-16') - ->string['name']->isIdenticalTo('Mi9TPro-TéléphoneM-2019-12-18-14-30-16') - ->string['itemtype']->isIdenticalTo('Phone') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']) - ->integer['items_id']->isGreaterThan(0); + $this->assertIsArray($agent); + $this->assertSame('Mi9TPro-TéléphoneM-2019-12-18-14-30-16', $agent['deviceid']); + $this->assertSame('Mi9TPro-TéléphoneM-2019-12-18-14-30-16', $agent['name']); + $this->assertSame('Phone', $agent['itemtype']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); + $this->assertGreaterThan(0, $agent['items_id']); //check matchedlogs $mlogs = new \RuleMatchedLog(); $found = $mlogs->find(); - $this->array($found)->hasSize(1); + $this->assertCount(1, $found); $criteria = [ 'FROM' => \RuleMatchedLog::getTable(), @@ -5270,32 +5326,32 @@ public function testImportPhone() ]; $iterator = $DB->request($criteria); - $this->integer(count($iterator))->isIdenticalTo(1); - $this->string($iterator->current()['name'])->isIdenticalTo('Phone import (by serial + uuid)'); - $this->string($iterator->current()['method'])->isIdenticalTo(\Glpi\Inventory\Request::INVENT_QUERY); + $this->assertCount(1, $iterator); + $this->assertSame('Phone import (by serial + uuid)', $iterator->current()['name']); + $this->assertSame(\Glpi\Inventory\Request::INVENT_QUERY, $iterator->current()['method']); //get phone models, manufacturer, ... $autoupdatesystems = $DB->request(['FROM' => \AutoupdateSystem::getTable(), 'WHERE' => ['name' => 'GLPI Native Inventory']])->current(); - $this->array($autoupdatesystems); + $this->assertIsArray($autoupdatesystems); $autoupdatesystems_id = $autoupdatesystems['id']; $cmodels = $DB->request(['FROM' => \PhoneModel::getTable(), 'WHERE' => ['name' => 'Mi 9T Pro']])->current(); - $this->array($cmodels); + $this->assertIsArray($cmodels); $computermodels_id = $cmodels['id']; $ctypes = $DB->request(['FROM' => \PhoneType::getTable(), 'WHERE' => ['name' => 'Mi 9T Pro']])->current(); - $this->array($ctypes); + $this->assertIsArray($ctypes); $computertypes_id = $ctypes['id']; $cmanuf = $DB->request(['FROM' => \Manufacturer::getTable(), 'WHERE' => ['name' => 'Xiaomi']])->current(); - $this->array($cmanuf); + $this->assertIsArray($cmanuf); $manufacturers_id = $cmanuf['id']; //check created phone $phones_id = $inventory->getAgent()->fields['items_id']; - $this->integer($phones_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $phones_id); $phone = new \Phone(); - $this->boolean($phone->getFromDB($phones_id))->isTrue(); + $this->assertTrue($phone->getFromDB($phones_id)); $expected = [ 'id' => $phones_id, @@ -5333,7 +5389,8 @@ public function testImportPhone() 'is_recursive' => 0, 'last_inventory_update' => $phone->fields['last_inventory_update'], ]; - $this->array($phone->fields)->isIdenticalTo($expected); + $this->assertIsArray($phone->fields); + $this->assertSame($expected, $phone->fields); //operating system $ios = new \Item_OperatingSystem(); @@ -5347,17 +5404,18 @@ public function testImportPhone() 'architecture' => 'arm64-v8a,armeabi-v7a,armeabi', 'servicepack' => null, ]; - $this->array($record)->isIdenticalTo($expected); + $this->assertIsArray($record); + $this->assertSame($expected, $record); //remote management $mgmt = new \Item_RemoteManagement(); $iterator = $mgmt->getFromItem($phone); - $this->integer(count($iterator))->isIdenticalTo(0); + $this->assertCount(0, $iterator); //volumes $idisks = new \Item_Disk(); $iterator = $idisks->getFromItem($phone); - $this->integer(count($iterator))->isIdenticalTo(4); + $this->assertCount(4, $iterator); $expecteds = [ [ @@ -5399,7 +5457,8 @@ public function testImportPhone() ]; ksort($volume); ksort($expected); - $this->array($volume)->isEqualTo($expected); + $this->assertIsArray($volume); + $this->assertEquals($expected, $volume); ++$i; } @@ -5411,7 +5470,7 @@ public function testImportPhone() 'itemtype' => 'Phone', ], ]); - $this->integer(count($iterator))->isIdenticalTo(1); + $this->assertCount(1, $iterator); $expecteds = [ [ @@ -5434,12 +5493,12 @@ public function testImportPhone() $netport = new \NetworkPort(); foreach ($iterator as $port) { $ports_id = $port['id']; - $this->boolean($netport->getFromDB($ports_id))->isTrue(); + $this->assertTrue($netport->getFromDB($ports_id)); $instantiation = $netport->getInstantiation(); if ($port['instantiation_type'] === null) { - $this->boolean($instantiation)->isFalse(); + $this->assertFalse($instantiation); } else { - $this->object($instantiation)->isInstanceOf($port['instantiation_type']); + $this->assertInstanceOf($port['instantiation_type'], $instantiation); } unset($port['id']); @@ -5472,7 +5531,8 @@ public function testImportPhone() 'lastup' => null ]; - $this->array($port)->isEqualTo($expected); + $this->assertIsArray($port); + $this->assertEquals($expected, $port); ++$i; //check for ips @@ -5498,12 +5558,12 @@ public function testImportPhone() ] ]); - $this->integer(count($ip_iterator))->isIdenticalTo(count($ips[$port['name']] ?? [])); + $this->assertCount(count($ips[$port['name']] ?? []), $ip_iterator); if (isset($ips[$port['name']])) { //FIXME: missing all ipv6 :( $ip = $ip_iterator->current(); - $this->integer((int)$ip['version'])->isIdenticalTo(4); - $this->string($ip['name'])->isIdenticalTo($ips[$port['name']]['v4']); + $this->assertSame(4, (int)$ip['version']); + $this->assertSame($ips[$port['name']]['v4'], $ip['name']); } } @@ -5545,7 +5605,7 @@ public function testImportPhone() ]; foreach ($expecteds as $type => $count) { - $this->integer(count($components[$type]))->isIdenticalTo($count, count($components[$type]) . ' ' . $type); + $this->assertCount($count, $components[$type], count($components[$type]) . ' ' . $type); } $expecteds = [ @@ -5701,13 +5761,14 @@ public function testImportPhone() } } } - $this->array($component)->isIdenticalTo($expected); + $this->assertIsArray($component); + $this->assertSame($expected, $component); } //software $isoft = new \Item_SoftwareVersion(); $iterator = $isoft->getFromItem($phone); - $this->integer(count($iterator))->isIdenticalTo(4); + $this->assertCount(4, $iterator); $expecteds = [ [ @@ -5732,11 +5793,14 @@ public function testImportPhone() $i = 0; foreach ($iterator as $soft) { $expected = $expecteds[$i]; - $this->array([ - 'softname' => $soft['softname'], - 'version' => $soft['version'], - 'dateinstall' => $soft['dateinstall'] - ])->isEqualTo($expected); + $this->assertEquals( + $expected, + [ + 'softname' => $soft['softname'], + 'version' => $soft['version'], + 'dateinstall' => $soft['dateinstall'] + ] + ); ++$i; } } @@ -5754,23 +5818,23 @@ public function testPartialComputerImport() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(6) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['version']->isIdenticalTo('FusionInventory-Agent_v2.5.2-1.fc31') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['action']->isIdenticalTo('inventory'); + $this->assertCount(6, $metadata); + $this->assertSame('glpixps-2018-07-09-09-07-13', $metadata['deviceid']); + $this->assertSame('FusionInventory-Agent_v2.5.2-1.fc31', $metadata['version']); + $this->assertSame('Computer', $metadata['itemtype']); + $this->assertSame('inventory', $metadata['action']); //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['name']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['version']->isIdenticalTo('2.5.2-1.fc31') - ->string['itemtype']->isIdenticalTo('Computer') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']); + $this->assertIsArray($agent); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['deviceid']); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['name']); + $this->assertSame('2.5.2-1.fc31', $agent['version']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); $computer = $this->checkComputer1($agent['items_id']); @@ -5832,25 +5896,27 @@ public function testDictionnaryManufacturer() 'condition' => 0, 'description' => '' ]); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); - $this->integer( + $this->assertGreaterThan( + 0, $criteria->add([ 'rules_id' => $rules_id, 'criteria' => 'name', 'condition' => \Rule::PATTERN_IS, 'pattern' => 'Dell Inc.' ]) - )->isGreaterThan(0); + ); - $this->integer( + $this->assertGreaterThan( + 0, $action->add([ 'rules_id' => $rules_id, 'action_type' => 'assign', 'field' => 'name', 'value' => 'Dictionary manufacturer' ]) - )->isGreaterThan(0); + ); $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_2.json')); @@ -5859,32 +5925,32 @@ public function testDictionnaryManufacturer() //check inventory metadata $metadata = $inventory->getMetadata(); - $this->array($metadata)->hasSize(5) - ->string['deviceid']->isIdenticalTo('acomputer-2021-01-26-14-32-36') - ->string['itemtype']->isIdenticalTo('Computer') - ->variable['port']->isIdenticalTo(null) - ->string['action']->isIdenticalTo('inventory'); + $this->assertCount(5, $metadata); + $this->assertSame('acomputer-2021-01-26-14-32-36', $metadata['deviceid']); + $this->assertSame('Computer', $metadata['itemtype']); + $this->assertNull($metadata['port']); + $this->assertSame('inventory', $metadata['action']); //check we add only one computer ++$nb_computers; - $this->integer(countElementsInTable(\Computer::getTable()))->isIdenticalTo($nb_computers); + $this->assertSame($nb_computers, countElementsInTable(\Computer::getTable())); //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->array($agent) - ->string['deviceid']->isIdenticalTo('acomputer-2021-01-26-14-32-36') - ->string['name']->isIdenticalTo('acomputer-2021-01-26-14-32-36') - ->string['itemtype']->isIdenticalTo('Computer') - ->integer['items_id']->isGreaterThan(0); + $this->assertIsArray($agent); + $this->assertSame('acomputer-2021-01-26-14-32-36', $agent['deviceid']); + $this->assertSame('acomputer-2021-01-26-14-32-36', $agent['name']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertGreaterThan(0, $agent['items_id']); //check created computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); + $this->assertTrue($computer->getFromDB($agent['items_id'])); $manufacturer = new \Manufacturer(); - $this->boolean($manufacturer->getFromDB($computer->fields['manufacturers_id']))->isTrue(); - $this->string($manufacturer->fields['name'])->isIdenticalTo('Dictionary manufacturer'); + $this->assertTrue($manufacturer->getFromDB($computer->fields['manufacturers_id'])); + $this->assertSame('Dictionary manufacturer', $manufacturer->fields['name']); } public function testDictionnaryOperatingSystem() @@ -5897,28 +5963,28 @@ public function testDictionnaryOperatingSystem() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check created computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); + $this->assertTrue($computer->getFromDB($agent['items_id'])); //check OS $item_operating = new Item_OperatingSystem(); - $this->boolean( + $this->assertTrue( $item_operating->getFromDBByCrit([ "itemtype" => 'Computer', "items_id" => $agent['items_id'], ]) - )->isTrue(); + ); $operating_system = new OperatingSystem(); - $this->boolean( + $this->assertTrue( $operating_system->getFromDB($item_operating->fields['operatingsystems_id']) - )->isTrue(); + ); - $this->string($operating_system->fields['name'])->isEqualTo("Fedora 31 (Workstation Edition)"); + $this->assertSame("Fedora 31 (Workstation Edition)", $operating_system->fields['name']); //create rule dictionnary operating system $rule = new \Rule(); @@ -5933,25 +5999,27 @@ public function testDictionnaryOperatingSystem() 'condition' => 0, 'description' => '' ]); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); - $this->integer( + $this->assertGreaterThan( + 0, $criteria->add([ 'rules_id' => $rules_id, 'criteria' => 'name', 'condition' => \Rule::PATTERN_CONTAIN, 'pattern' => 'Fedora 31' ]) - )->isGreaterThan(0); + ); - $this->integer( + $this->assertGreaterThan( + 0, $action->add([ 'rules_id' => $rules_id, 'action_type' => 'assign', 'field' => 'name', 'value' => 'Ubuntu' ]) - )->isGreaterThan(0); + ); //redo an inventory $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_1.json')); @@ -5959,28 +6027,28 @@ public function testDictionnaryOperatingSystem() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check updated computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); + $this->assertTrue($computer->getFromDB($agent['items_id'])); //check OS $item_operating = new Item_OperatingSystem(); - $this->boolean( + $this->assertTrue( $item_operating->getFromDBByCrit([ "itemtype" => 'Computer', "items_id" => $agent['items_id'], ]) - )->isTrue(); + ); $operating_system = new OperatingSystem(); - $this->boolean( + $this->assertTrue( $operating_system->getFromDB($item_operating->fields['operatingsystems_id']) - )->isTrue(); + ); - $this->string($operating_system->fields['name'])->isEqualTo("Ubuntu"); + $this->assertSame("Ubuntu", $operating_system->fields['name']); } public function testDictionnaryOperatingSystemVersion() @@ -5993,29 +6061,29 @@ public function testDictionnaryOperatingSystemVersion() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check created computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); + $this->assertTrue($computer->getFromDB($agent['items_id'])); //check OS $item_operating = new Item_OperatingSystem(); - $this->boolean( + $this->assertTrue( $item_operating->getFromDBByCrit([ "itemtype" => 'Computer', "items_id" => $agent['items_id'], ]) - )->isTrue(); + ); $operating_system_version = new OperatingSystemVersion(); - $this->boolean( + $this->assertTrue( $operating_system_version->getFromDB($item_operating->fields['operatingsystemversions_id']) - )->isTrue(); + ); //check if is original value - $this->string($operating_system_version->fields['name'])->isEqualTo("31 (Workstation Edition)"); + $this->assertSame("31 (Workstation Edition)", $operating_system_version->fields['name']); //create rule dictionnary operating system $rule = new \Rule(); @@ -6030,25 +6098,27 @@ public function testDictionnaryOperatingSystemVersion() 'condition' => 0, 'description' => '' ]); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); - $this->integer( + $this->assertGreaterThan( + 0, $criteria->add([ 'rules_id' => $rules_id, 'criteria' => 'name', 'condition' => \Rule::PATTERN_CONTAIN, 'pattern' => '31 (Workstation Edition)' ]) - )->isGreaterThan(0); + ); - $this->integer( + $this->assertGreaterThan( + 0, $action->add([ 'rules_id' => $rules_id, 'action_type' => 'assign', 'field' => 'name', 'value' => 'New version' ]) - )->isGreaterThan(0); + ); //redo an inventory $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_1.json')); @@ -6056,29 +6126,29 @@ public function testDictionnaryOperatingSystemVersion() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check updated computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); + $this->assertTrue($computer->getFromDB($agent['items_id'])); //check OS $item_operating = new Item_OperatingSystem(); - $this->boolean( + $this->assertTrue( $item_operating->getFromDBByCrit([ "itemtype" => 'Computer', "items_id" => $agent['items_id'], ]) - )->isTrue(); + ); $operating_system_version = new OperatingSystemVersion(); - $this->boolean( + $this->assertTrue( $operating_system_version->getFromDB($item_operating->fields['operatingsystemversions_id']) - )->isTrue(); + ); //check if is specific value - $this->string($operating_system_version->fields['name'])->isEqualTo("New version"); + $this->assertSame("New version", $operating_system_version->fields['name']); } public function testDictionnaryOperatingSystemArchitecture() @@ -6091,28 +6161,28 @@ public function testDictionnaryOperatingSystemArchitecture() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check created computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); + $this->assertTrue($computer->getFromDB($agent['items_id'])); //check OS $item_operating = new Item_OperatingSystem(); - $this->boolean( + $this->assertTrue( $item_operating->getFromDBByCrit([ "itemtype" => 'Computer', "items_id" => $agent['items_id'], ]) - )->isTrue(); + ); $operating_arch = new OperatingSystemArchitecture(); - $this->boolean( + $this->assertTrue( $operating_arch->getFromDB($item_operating->fields['operatingsystemarchitectures_id']) - )->isTrue(); + ); //check if is original value - $this->string($operating_arch->fields['name'])->isEqualTo("x86_64"); + $this->assertSame("x86_64", $operating_arch->fields['name']); //create rule dictionnary operating system $rule = new \Rule(); @@ -6127,25 +6197,27 @@ public function testDictionnaryOperatingSystemArchitecture() 'condition' => 0, 'description' => '' ]); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); - $this->integer( + $this->assertGreaterThan( + 0, $criteria->add([ 'rules_id' => $rules_id, 'criteria' => 'name', 'condition' => \Rule::PATTERN_CONTAIN, 'pattern' => 'x86_64' ]) - )->isGreaterThan(0); + ); - $this->integer( + $this->assertGreaterThan( + 0, $action->add([ 'rules_id' => $rules_id, 'action_type' => 'assign', 'field' => 'name', 'value' => 'New arch' ]) - )->isGreaterThan(0); + ); //redo an inventory $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_1.json')); @@ -6153,29 +6225,29 @@ public function testDictionnaryOperatingSystemArchitecture() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check updated computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); + $this->assertTrue($computer->getFromDB($agent['items_id'])); //check OS $item_operating = new Item_OperatingSystem(); - $this->boolean( + $this->assertTrue( $item_operating->getFromDBByCrit([ "itemtype" => 'Computer', "items_id" => $agent['items_id'], ]) - )->isTrue(); + ); $operating_arch = new OperatingSystemArchitecture(); - $this->boolean( + $this->assertTrue( $operating_arch->getFromDB($item_operating->fields['operatingsystemarchitectures_id']) - )->isTrue(); + ); //check if is specific value - $this->string($operating_arch->fields['name'])->isEqualTo("New arch"); + $this->assertSame("New arch", $operating_arch->fields['name']); } public function testDictionnaryOperatingSystemServicePack() @@ -6188,24 +6260,24 @@ public function testDictionnaryOperatingSystemServicePack() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check created computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); + $this->assertTrue($computer->getFromDB($agent['items_id'])); //check OS $item_operating = new Item_OperatingSystem(); - $this->boolean( + $this->assertTrue( $item_operating->getFromDBByCrit([ "itemtype" => 'Computer', "items_id" => $agent['items_id'], ]) - )->isTrue(); + ); //No service pack from linux (normal) - $this->integer($item_operating->fields['operatingsystemservicepacks_id'])->isEqualto(0); + $this->assertEquals(0, $item_operating->fields['operatingsystemservicepacks_id']); //create rule dictionnary operating system $rule = new \Rule(); @@ -6220,26 +6292,28 @@ public function testDictionnaryOperatingSystemServicePack() 'condition' => 0, 'description' => '' ]); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria on os_name - $this->integer( + $this->assertGreaterThan( + 0, $criteria->add([ 'rules_id' => $rules_id, 'criteria' => 'os_name', 'condition' => \Rule::PATTERN_CONTAIN, 'pattern' => 'Fedora 31' ]) - )->isGreaterThan(0); + ); - $this->integer( + $this->assertGreaterThan( + 0, $action->add([ 'rules_id' => $rules_id, 'action_type' => 'assign', 'field' => 'name', 'value' => 'New service_pack' ]) - )->isGreaterThan(0); + ); //redo an inventory $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_1.json')); @@ -6247,28 +6321,28 @@ public function testDictionnaryOperatingSystemServicePack() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check updated computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); + $this->assertTrue($computer->getFromDB($agent['items_id'])); //check OS $item_operating = new Item_OperatingSystem(); - $this->boolean( + $this->assertTrue( $item_operating->getFromDBByCrit([ "itemtype" => 'Computer', "items_id" => $agent['items_id'], ]) - )->isTrue(); + ); $operating_service_pack = new OperatingSystemServicePack(); - $this->boolean( + $this->assertTrue( $operating_service_pack->getFromDB($item_operating->fields['operatingsystemservicepacks_id']) - )->isTrue(); + ); //check if is specific value - $this->string($operating_service_pack->fields['name'])->isEqualTo("New service_pack"); + $this->assertSame("New service_pack", $operating_service_pack->fields['name']); } public function testImportStatusAfterClean() @@ -6282,12 +6356,12 @@ public function testImportStatusAfterClean() $inv_states_id = $state->add([ 'name' => 'Has been inventoried' ]); - $this->integer($inv_states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $inv_states_id); $cleaned_states_id = $state->add([ 'name' => 'Has been cleaned' ]); - $this->integer($cleaned_states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $cleaned_states_id); \Config::setConfigurationValues( 'inventory', @@ -6308,53 +6382,53 @@ public function testImportStatusAfterClean() //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); $agents_id = $agent['id']; - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['name']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['version']->isIdenticalTo('2.5.2-1.fc31') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['tag']->isIdenticalTo('000005') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']) - ->integer['items_id']->isGreaterThan(0); + $this->assertIsArray($agent); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['deviceid']); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['name']); + $this->assertSame('2.5.2-1.fc31', $agent['version']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame('000005', $agent['tag']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); + $this->assertGreaterThan(0, $agent['items_id']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check states has been set - $this->integer($computer->fields['states_id'])->isIdenticalTo($inv_states_id); + $this->assertSame($inv_states_id, $computer->fields['states_id']); $lockedfield = new \Lockedfield(); - $this->boolean($lockedfield->isHandled($computer))->isTrue(); - $this->array($lockedfield->getLockedValues($computer->getType(), $computers_id))->isEmpty(); + $this->assertTrue($lockedfield->isHandled($computer)); + $this->assertSame([], $lockedfield->getLockedValues($computer->getType(), $computers_id)); //set agent inventory date in past $invdate = new \DateTime($agent['last_contact']); $invdate->sub(new \DateInterval('P1Y')); $agent = new \Agent(); - $this->boolean( + $this->assertTrue( $agent->update([ 'id' => $agents_id, 'last_contact' => $invdate->format('Y-m-d H:i:s') ]) - )->isTrue(); + ); //cleanup old agents $name = \CronTask::launch(-\CronTask::MODE_INTERNAL, 1, 'Cleanoldagents'); - $this->string($name)->isIdenticalTo('Cleanoldagents'); + $this->assertSame('Cleanoldagents', $name); //check computer state has been updated - $this->boolean($computer->getFromDB($computers_id))->isTrue(); - $this->integer($computer->fields['states_id'])->isIdenticalTo($cleaned_states_id); + $this->assertTrue($computer->getFromDB($computers_id)); + $this->assertSame($cleaned_states_id, $computer->fields['states_id']); - $this->boolean($lockedfield->isHandled($computer))->isTrue(); - $this->array($lockedfield->getLockedValues($computer->getType(), $computers_id))->isEmpty(); + $this->assertTrue($lockedfield->isHandled($computer)); + $this->assertSame([], $lockedfield->getLockedValues($computer->getType(), $computers_id)); } @@ -6369,13 +6443,13 @@ public function testDefaultStatesOnAddWithGlobalLock() $default_states_id = $default_states->add([ 'name' => 'Has been inventoried' ]); - $this->integer($default_states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $default_states_id); $other_state = new \State(); $other_states_id = $other_state->add([ 'name' => 'Another states' ]); - $this->integer($other_states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $other_states_id); \Config::setConfigurationValues( 'inventory', @@ -6392,7 +6466,7 @@ public function testDefaultStatesOnAddWithGlobalLock() 'field' => 'states_id', 'is_global' => 1 ]); - $this->integer($lock_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $lock_id); $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_1.json')); $this->doInventory($json); @@ -6400,38 +6474,38 @@ public function testDefaultStatesOnAddWithGlobalLock() //check created agent $agenttype = $DB->request(['FROM' => \AgentType::getTable(), 'WHERE' => ['name' => 'Core']])->current(); $agents = $DB->request(['FROM' => \Agent::getTable()]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); $agents_id = $agent['id']; - $this->array($agent) - ->string['deviceid']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['name']->isIdenticalTo('glpixps-2018-07-09-09-07-13') - ->string['version']->isIdenticalTo('2.5.2-1.fc31') - ->string['itemtype']->isIdenticalTo('Computer') - ->string['tag']->isIdenticalTo('000005') - ->integer['agenttypes_id']->isIdenticalTo($agenttype['id']) - ->integer['items_id']->isGreaterThan(0); + $this->assertIsArray($agent); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['deviceid']); + $this->assertSame('glpixps-2018-07-09-09-07-13', $agent['name']); + $this->assertSame('2.5.2-1.fc31', $agent['version']); + $this->assertSame('Computer', $agent['itemtype']); + $this->assertSame('000005', $agent['tag']); + $this->assertSame($agenttype['id'], $agent['agenttypes_id']); + $this->assertGreaterThan(0, $agent['items_id']); //check created computer $computers_id = $agent['items_id']; - $this->integer($computers_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $computers_id); $computer = new \Computer(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check default states has been set - $this->integer($computer->fields['states_id'])->isIdenticalTo($default_states_id); + $this->assertSame($default_states_id, $computer->fields['states_id']); //update states - $this->boolean($computer->update(['id' => $computers_id, 'states_id' => $other_states_id]))->isTrue(); + $this->assertTrue($computer->update(['id' => $computers_id, 'states_id' => $other_states_id])); //redo inventory $json = json_decode(file_get_contents(self::INV_FIXTURES . 'computer_1.json')); $this->doInventory($json); //reload computer - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertTrue($computer->getFromDB($computers_id)); //check is same on update - $this->integer($computer->fields['states_id'])->isIdenticalTo($other_states_id); + $this->assertSame($other_states_id, $computer->fields['states_id']); } @@ -6450,7 +6524,7 @@ public function testOtherSerialFromTag() $rule = new \Rule(); $rules_id = $rule->add($input_rule); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria $input_criteria = [ @@ -6461,7 +6535,7 @@ public function testOtherSerialFromTag() ]; $rule_criteria = new \RuleCriteria(); $rule_criteria_id = $rule_criteria->add($input_criteria); - $this->integer($rule_criteria_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_criteria_id); //create action $input_action = [ @@ -6472,7 +6546,7 @@ public function testOtherSerialFromTag() ]; $rule_action = new \RuleAction(); $rule_action_id = $rule_action->add($input_action); - $this->integer($rule_action_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action_id); $tag = 'a_tag'; $xml_source = " @@ -6497,14 +6571,14 @@ public function testOtherSerialFromTag() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable(), "WHERE" => ['deviceid' => 'test_otherserial_from_tag']]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->string($agent['tag'])->isIdenticalTo($tag); + $this->assertSame($tag, $agent['tag']); //check created computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->string($computer->fields['otherserial'])->isIdenticalTo($tag); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertSame($tag, $computer->fields['otherserial']); //redo inventory by updating tag @@ -6531,14 +6605,14 @@ public function testOtherSerialFromTag() //check agent $agents = $DB->request(['FROM' => \Agent::getTable(), "WHERE" => ['deviceid' => 'test_otherserial_from_tag']]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); - $this->string($agent['tag'])->isIdenticalTo($tag); + $this->assertSame($tag, $agent['tag']); //check created computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->string($computer->fields['otherserial'])->isIdenticalTo($tag); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertSame($tag, $computer->fields['otherserial']); } public function testBusinessRuleOnAddComputer() @@ -6548,11 +6622,11 @@ public function testBusinessRuleOnAddComputer() //prepare rule contents $state = new \State(); $states_id = $state->add(['name' => 'Test status']); - $this->integer($states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $states_id); $location = new \Location(); $locations_id = $location->add(['name' => 'Test location']); - $this->integer($locations_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $locations_id); //create rule $input_rule = [ @@ -6565,7 +6639,7 @@ public function testBusinessRuleOnAddComputer() $rule = new \Rule(); $rules_id = $rule->add($input_rule); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria $input_criteria = [ @@ -6576,7 +6650,7 @@ public function testBusinessRuleOnAddComputer() ]; $rule_criteria = new \RuleCriteria(); $rule_criteria_id = $rule_criteria->add($input_criteria); - $this->integer($rule_criteria_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_criteria_id); //create actions $input_action = [ @@ -6586,7 +6660,7 @@ public function testBusinessRuleOnAddComputer() 'value' => $states_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -6595,7 +6669,7 @@ public function testBusinessRuleOnAddComputer() 'value' => $locations_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -6604,17 +6678,17 @@ public function testBusinessRuleOnAddComputer() 'value' => 'A comment' ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); //ensure business rule work on regular Computer add $computer = new \Computer(); $computers_id = $computer->add(['name' => 'Test computer', 'entities_id' => 0]); - $this->integer($computers_id)->isGreaterThan(0); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertGreaterThan(0, $computers_id); + $this->assertTrue($computer->getFromDB($computers_id)); - $this->string($computer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($computer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertSame('A comment', $computer->fields['comment']); + $this->assertSame($states_id, $computer->fields['states_id']); + $this->assertSame($locations_id, $computer->fields['locations_id']); //inventory a new computer $xml_source = " @@ -6637,22 +6711,22 @@ public function testBusinessRuleOnAddComputer() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable(), "WHERE" => ['deviceid' => 'test_setstatusifinventory']]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check created computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->string($computer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($computer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertSame('A comment', $computer->fields['comment']); + $this->assertSame($states_id, $computer->fields['states_id']); + $this->assertSame($locations_id, $computer->fields['locations_id']); //redo inventory $this->doInventory($xml_source, true); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->string($computer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($computer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertSame('A comment', $computer->fields['comment']); + $this->assertSame($states_id, $computer->fields['states_id']); + $this->assertSame($locations_id, $computer->fields['locations_id']); } public function testBusinessRuleOnUpdateComputer() @@ -6662,11 +6736,11 @@ public function testBusinessRuleOnUpdateComputer() //prepare rule contents $state = new \State(); $states_id = $state->add(['name' => 'Test status']); - $this->integer($states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $states_id); $location = new \Location(); $locations_id = $location->add(['name' => 'Test location']); - $this->integer($locations_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $locations_id); //create rule $input_rule = [ @@ -6679,7 +6753,7 @@ public function testBusinessRuleOnUpdateComputer() $rule = new \Rule(); $rules_id = $rule->add($input_rule); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria $input_criteria = [ @@ -6690,7 +6764,7 @@ public function testBusinessRuleOnUpdateComputer() ]; $rule_criteria = new \RuleCriteria(); $rule_criteria_id = $rule_criteria->add($input_criteria); - $this->integer($rule_criteria_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_criteria_id); //create actions $input_action = [ @@ -6700,7 +6774,7 @@ public function testBusinessRuleOnUpdateComputer() 'value' => $states_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -6709,7 +6783,7 @@ public function testBusinessRuleOnUpdateComputer() 'value' => $locations_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -6718,30 +6792,30 @@ public function testBusinessRuleOnUpdateComputer() 'value' => 'A comment' ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); //ensure business rule work on regular Computer add $computer = new \Computer(); $computers_id = $computer->add(['name' => 'Test computer', 'entities_id' => 0]); - $this->integer($computers_id)->isGreaterThan(0); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertGreaterThan(0, $computers_id); + $this->assertTrue($computer->getFromDB($computers_id)); - $this->variable($computer->fields['comment'])->isNull(); - $this->integer($computer->fields['states_id'])->isIdenticalTo(0); - $this->integer($computer->fields['locations_id'])->isIdenticalTo(0); + $this->assertNull($computer->fields['comment']); + $this->assertSame(0, $computer->fields['states_id']); + $this->assertSame(0, $computer->fields['locations_id']); //update computer - $this->boolean( + $this->assertTrue( $computer->update([ 'id' => $computers_id, 'comment' => 'Another comment' ]) - )->isTrue(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + ); + $this->assertTrue($computer->getFromDB($computers_id)); - $this->string($computer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($computer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertSame('A comment', $computer->fields['comment']); + $this->assertSame($states_id, $computer->fields['states_id']); + $this->assertSame($locations_id, $computer->fields['locations_id']); //inventory a new computer $xml_source = " @@ -6764,22 +6838,22 @@ public function testBusinessRuleOnUpdateComputer() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable(), "WHERE" => ['deviceid' => 'test_setstatusifinventory']]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check created computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->variable($computer->fields['comment'])->isNull(); - $this->integer($computer->fields['states_id'])->isIdenticalTo(0); - $this->integer($computer->fields['locations_id'])->isIdenticalTo(0); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertNull($computer->fields['comment']); + $this->assertSame(0, $computer->fields['states_id']); + $this->assertSame(0, $computer->fields['locations_id']); //redo inventory $this->doInventory($xml_source, true); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->string($computer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($computer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertSame('A comment', $computer->fields['comment']); + $this->assertSame($states_id, $computer->fields['states_id']); + $this->assertSame($locations_id, $computer->fields['locations_id']); } public function testBusinessRuleOnAddAndOnUpdateComputer() @@ -6789,11 +6863,11 @@ public function testBusinessRuleOnAddAndOnUpdateComputer() //prepare rule contents $state = new \State(); $states_id = $state->add(['name' => 'Test status']); - $this->integer($states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $states_id); $location = new \Location(); $locations_id = $location->add(['name' => 'Test location']); - $this->integer($locations_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $locations_id); //create rule $input_rule = [ @@ -6806,7 +6880,7 @@ public function testBusinessRuleOnAddAndOnUpdateComputer() $rule = new \Rule(); $rules_id = $rule->add($input_rule); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria $input_criteria = [ @@ -6817,7 +6891,7 @@ public function testBusinessRuleOnAddAndOnUpdateComputer() ]; $rule_criteria = new \RuleCriteria(); $rule_criteria_id = $rule_criteria->add($input_criteria); - $this->integer($rule_criteria_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_criteria_id); //create actions $input_action = [ @@ -6827,7 +6901,7 @@ public function testBusinessRuleOnAddAndOnUpdateComputer() 'value' => $states_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -6836,7 +6910,7 @@ public function testBusinessRuleOnAddAndOnUpdateComputer() 'value' => $locations_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -6845,30 +6919,30 @@ public function testBusinessRuleOnAddAndOnUpdateComputer() 'value' => 'A comment' ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); //ensure business rule work on regular Computer add $computer = new \Computer(); $computers_id = $computer->add(['name' => 'Test computer', 'entities_id' => 0]); - $this->integer($computers_id)->isGreaterThan(0); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + $this->assertGreaterThan(0, $computers_id); + $this->assertTrue($computer->getFromDB($computers_id)); - $this->string($computer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($computer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertSame('A comment', $computer->fields['comment']); + $this->assertSame($states_id, $computer->fields['states_id']); + $this->assertSame($locations_id, $computer->fields['locations_id']); //update computer - $this->boolean( + $this->assertTrue( $computer->update([ 'id' => $computers_id, 'comment' => 'Another comment' ]) - )->isTrue(); - $this->boolean($computer->getFromDB($computers_id))->isTrue(); + ); + $this->assertTrue($computer->getFromDB($computers_id)); - $this->string($computer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($computer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertSame('A comment', $computer->fields['comment']); + $this->assertSame($states_id, $computer->fields['states_id']); + $this->assertSame($locations_id, $computer->fields['locations_id']); //inventory a new computer $xml_source = " @@ -6891,22 +6965,22 @@ public function testBusinessRuleOnAddAndOnUpdateComputer() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable(), "WHERE" => ['deviceid' => 'test_setstatusifinventory']]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check created computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->string($computer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($computer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertSame('A comment', $computer->fields['comment']); + $this->assertSame($states_id, $computer->fields['states_id']); + $this->assertSame($locations_id, $computer->fields['locations_id']); //redo inventory $this->doInventory($xml_source, true); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->string($computer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($computer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertSame('A comment', $computer->fields['comment']); + $this->assertSame($states_id, $computer->fields['states_id']); + $this->assertSame($locations_id, $computer->fields['locations_id']); } public function testBusinessRuleOnAddNetworkEquipment() @@ -6916,11 +6990,11 @@ public function testBusinessRuleOnAddNetworkEquipment() //prepare rule contents $state = new \State(); $states_id = $state->add(['name' => 'Test status']); - $this->integer($states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $states_id); $location = new \Location(); $locations_id = $location->add(['name' => 'Test location']); - $this->integer($locations_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $locations_id); //create rule $input_rule = [ @@ -6933,7 +7007,7 @@ public function testBusinessRuleOnAddNetworkEquipment() $rule = new \Rule(); $rules_id = $rule->add($input_rule); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria $input_criteria = [ @@ -6944,7 +7018,7 @@ public function testBusinessRuleOnAddNetworkEquipment() ]; $rule_criteria = new \RuleCriteria(); $rule_criteria_id = $rule_criteria->add($input_criteria); - $this->integer($rule_criteria_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_criteria_id); //create actions $input_action = [ @@ -6954,7 +7028,7 @@ public function testBusinessRuleOnAddNetworkEquipment() 'value' => $states_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -6963,7 +7037,7 @@ public function testBusinessRuleOnAddNetworkEquipment() 'value' => $locations_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -6972,17 +7046,17 @@ public function testBusinessRuleOnAddNetworkEquipment() 'value' => 'A comment' ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); //ensure business rule work on regular Network Equipment add $neteq = new \NetworkEquipment(); $networkeequipments_id = $neteq->add(['name' => 'Test network equipment', 'entities_id' => 0]); - $this->integer($networkeequipments_id)->isGreaterThan(0); - $this->boolean($neteq->getFromDB($networkeequipments_id))->isTrue(); + $this->assertGreaterThan(0, $networkeequipments_id); + $this->assertTrue($neteq->getFromDB($networkeequipments_id)); - $this->string($neteq->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($neteq->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($neteq->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertSame('A comment', $neteq->fields['comment']); + $this->assertSame($states_id, $neteq->fields['states_id']); + $this->assertSame($locations_id, $neteq->fields['locations_id']); //inventory a new network equipment $xml_source = " @@ -7028,18 +7102,18 @@ public function testBusinessRuleOnAddNetworkEquipment() //check created networkequipment $neteq = new \NetworkEquipment(); - $this->boolean($neteq->getFromDBByCrit(['serial' => 'SSI1912014B']))->isTrue(); - $this->string($neteq->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($neteq->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($neteq->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertTrue($neteq->getFromDBByCrit(['serial' => 'SSI1912014B'])); + $this->assertSame('A comment', $neteq->fields['comment']); + $this->assertSame($states_id, $neteq->fields['states_id']); + $this->assertSame($locations_id, $neteq->fields['locations_id']); //redo inventory $this->doInventory($xml_source, true); - $this->boolean($neteq->getFromDBByCrit(['serial' => 'SSI1912014B']))->isTrue(); - $this->string($neteq->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($neteq->fields['states_id'])->isIdenticalTo($states_id); + $this->assertTrue($neteq->getFromDBByCrit(['serial' => 'SSI1912014B'])); + $this->assertSame('A comment', $neteq->fields['comment']); + $this->assertSame($states_id, $neteq->fields['states_id']); //location is not set by rule on update, but is set from inventory data - $this->integer($neteq->fields['locations_id'])->isIdenticalTo(getItemByTypeName(\Location::class, 'paris.pa3', true)); + $this->assertSame(getItemByTypeName(\Location::class, 'paris.pa3', true), $neteq->fields['locations_id']); } public function testBusinessRuleOnUpdateNetworkEquipment() @@ -7049,11 +7123,11 @@ public function testBusinessRuleOnUpdateNetworkEquipment() //prepare rule contents $state = new \State(); $states_id = $state->add(['name' => 'Test status']); - $this->integer($states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $states_id); $location = new \Location(); $locations_id = $location->add(['name' => 'Test location']); - $this->integer($locations_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $locations_id); //create rule $input_rule = [ @@ -7066,7 +7140,7 @@ public function testBusinessRuleOnUpdateNetworkEquipment() $rule = new \Rule(); $rules_id = $rule->add($input_rule); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria $input_criteria = [ @@ -7077,7 +7151,7 @@ public function testBusinessRuleOnUpdateNetworkEquipment() ]; $rule_criteria = new \RuleCriteria(); $rule_criteria_id = $rule_criteria->add($input_criteria); - $this->integer($rule_criteria_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_criteria_id); //create actions $input_action = [ @@ -7087,7 +7161,7 @@ public function testBusinessRuleOnUpdateNetworkEquipment() 'value' => $states_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -7096,7 +7170,7 @@ public function testBusinessRuleOnUpdateNetworkEquipment() 'value' => $locations_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -7105,30 +7179,30 @@ public function testBusinessRuleOnUpdateNetworkEquipment() 'value' => 'A comment' ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); //ensure business rule work on regular Network equipment add $neteq = new \NetworkEquipment(); $networkequipments_id = $neteq->add(['name' => 'Test network equipment', 'entities_id' => 0]); - $this->integer($networkequipments_id)->isGreaterThan(0); - $this->boolean($neteq->getFromDB($networkequipments_id))->isTrue(); + $this->assertGreaterThan(0, $networkequipments_id); + $this->assertTrue($neteq->getFromDB($networkequipments_id)); - $this->variable($neteq->fields['comment'])->isNull(); - $this->integer($neteq->fields['states_id'])->isIdenticalTo(0); - $this->integer($neteq->fields['locations_id'])->isIdenticalTo(0); + $this->assertNull($neteq->fields['comment']); + $this->assertSame(0, $neteq->fields['states_id']); + $this->assertSame(0, $neteq->fields['locations_id']); //update network equipment - $this->boolean( + $this->assertTrue( $neteq->update([ 'id' => $networkequipments_id, 'comment' => 'Another comment' ]) - )->isTrue(); - $this->boolean($neteq->getFromDB($networkequipments_id))->isTrue(); + ); + $this->assertTrue($neteq->getFromDB($networkequipments_id)); - $this->string($neteq->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($neteq->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($neteq->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertSame('A comment', $neteq->fields['comment']); + $this->assertSame($states_id, $neteq->fields['states_id']); + $this->assertSame($locations_id, $neteq->fields['locations_id']); //inventory a new network equipment $xml_source = " @@ -7174,17 +7248,17 @@ public function testBusinessRuleOnUpdateNetworkEquipment() //check created network equipment $neteq = new \NetworkEquipment(); - $this->boolean($neteq->getFromDBByCrit(['serial' => 'SSI1912014B']))->isTrue(); - $this->variable($neteq->fields['comment'])->isNull(); - $this->integer($neteq->fields['states_id'])->isIdenticalTo(0); - $this->integer($neteq->fields['locations_id'])->isIdenticalTo(getItemByTypeName(\Location::class, 'paris.pa3', true)); + $this->assertTrue($neteq->getFromDBByCrit(['serial' => 'SSI1912014B'])); + $this->assertNull($neteq->fields['comment']); + $this->assertSame(0, $neteq->fields['states_id']); + $this->assertSame(getItemByTypeName(\Location::class, 'paris.pa3', true), $neteq->fields['locations_id']); //redo inventory $this->doInventory($xml_source, true); - $this->boolean($neteq->getFromDBByCrit(['serial' => 'SSI1912014B']))->isTrue(); - $this->string($neteq->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($neteq->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($neteq->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertTrue($neteq->getFromDBByCrit(['serial' => 'SSI1912014B'])); + $this->assertSame('A comment', $neteq->fields['comment']); + $this->assertSame($states_id, $neteq->fields['states_id']); + $this->assertSame($locations_id, $neteq->fields['locations_id']); } public function testBusinessRuleOnAddAndOnUpdateNetworkEquipment() @@ -7194,11 +7268,11 @@ public function testBusinessRuleOnAddAndOnUpdateNetworkEquipment() //prepare rule contents $state = new \State(); $states_id = $state->add(['name' => 'Test status']); - $this->integer($states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $states_id); $location = new \Location(); $locations_id = $location->add(['name' => 'Test location']); - $this->integer($locations_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $locations_id); //create rule $input_rule = [ @@ -7211,7 +7285,7 @@ public function testBusinessRuleOnAddAndOnUpdateNetworkEquipment() $rule = new \Rule(); $rules_id = $rule->add($input_rule); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria $input_criteria = [ @@ -7222,7 +7296,7 @@ public function testBusinessRuleOnAddAndOnUpdateNetworkEquipment() ]; $rule_criteria = new \RuleCriteria(); $rule_criteria_id = $rule_criteria->add($input_criteria); - $this->integer($rule_criteria_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_criteria_id); //create actions $input_action = [ @@ -7232,7 +7306,7 @@ public function testBusinessRuleOnAddAndOnUpdateNetworkEquipment() 'value' => $states_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -7241,7 +7315,7 @@ public function testBusinessRuleOnAddAndOnUpdateNetworkEquipment() 'value' => $locations_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -7250,30 +7324,30 @@ public function testBusinessRuleOnAddAndOnUpdateNetworkEquipment() 'value' => 'A comment' ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); //ensure business rule work on regular Network equipment add $neteq = new \NetworkEquipment(); $networkequipments_id = $neteq->add(['name' => 'Test network equipment', 'entities_id' => 0]); - $this->integer($networkequipments_id)->isGreaterThan(0); - $this->boolean($neteq->getFromDB($networkequipments_id))->isTrue(); + $this->assertGreaterThan(0, $networkequipments_id); + $this->assertTrue($neteq->getFromDB($networkequipments_id)); - $this->string($neteq->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($neteq->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($neteq->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertSame('A comment', $neteq->fields['comment']); + $this->assertSame($states_id, $neteq->fields['states_id']); + $this->assertSame($locations_id, $neteq->fields['locations_id']); //update network equipment - $this->boolean( + $this->assertTrue( $neteq->update([ 'id' => $networkequipments_id, 'comment' => 'Another comment' ]) - )->isTrue(); - $this->boolean($neteq->getFromDB($networkequipments_id))->isTrue(); + ); + $this->assertTrue($neteq->getFromDB($networkequipments_id)); - $this->string($neteq->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($neteq->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($neteq->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertSame('A comment', $neteq->fields['comment']); + $this->assertSame($states_id, $neteq->fields['states_id']); + $this->assertSame($locations_id, $neteq->fields['locations_id']); //inventory a new network equipment $xml_source = " @@ -7319,17 +7393,17 @@ public function testBusinessRuleOnAddAndOnUpdateNetworkEquipment() //check created network equipment $neteq = new \NetworkEquipment(); - $this->boolean($neteq->getFromDBByCrit(['serial' => 'SSI1912014B']))->isTrue(); - $this->string($neteq->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($neteq->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($neteq->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertTrue($neteq->getFromDBByCrit(['serial' => 'SSI1912014B'])); + $this->assertSame('A comment', $neteq->fields['comment']); + $this->assertSame($states_id, $neteq->fields['states_id']); + $this->assertSame($locations_id, $neteq->fields['locations_id']); //redo inventory $this->doInventory($xml_source, true); - $this->boolean($neteq->getFromDBByCrit(['serial' => 'SSI1912014B']))->isTrue(); - $this->string($neteq->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($neteq->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($neteq->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertTrue($neteq->getFromDBByCrit(['serial' => 'SSI1912014B'])); + $this->assertSame('A comment', $neteq->fields['comment']); + $this->assertSame($states_id, $neteq->fields['states_id']); + $this->assertSame($locations_id, $neteq->fields['locations_id']); } public function testBusinessRuleOnAddPrinter() @@ -7339,11 +7413,11 @@ public function testBusinessRuleOnAddPrinter() //prepare rule contents $state = new \State(); $states_id = $state->add(['name' => 'Test status']); - $this->integer($states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $states_id); $location = new \Location(); $locations_id = $location->add(['name' => 'Test location']); - $this->integer($locations_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $locations_id); //create rule $input_rule = [ @@ -7356,7 +7430,7 @@ public function testBusinessRuleOnAddPrinter() $rule = new \Rule(); $rules_id = $rule->add($input_rule); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria $input_criteria = [ @@ -7367,7 +7441,7 @@ public function testBusinessRuleOnAddPrinter() ]; $rule_criteria = new \RuleCriteria(); $rule_criteria_id = $rule_criteria->add($input_criteria); - $this->integer($rule_criteria_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_criteria_id); //create actions $input_action = [ @@ -7377,7 +7451,7 @@ public function testBusinessRuleOnAddPrinter() 'value' => $states_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -7386,7 +7460,7 @@ public function testBusinessRuleOnAddPrinter() 'value' => $locations_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -7395,17 +7469,17 @@ public function testBusinessRuleOnAddPrinter() 'value' => 'A comment' ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); //ensure business rule work on regular printer add $printer = new \Printer(); $printers_id = $printer->add(['name' => 'Test printer', 'entities_id' => 0]); - $this->integer($printers_id)->isGreaterThan(0); - $this->boolean($printer->getFromDB($printers_id))->isTrue(); + $this->assertGreaterThan(0, $printers_id); + $this->assertTrue($printer->getFromDB($printers_id)); - $this->string($printer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($printer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($printer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertSame('A comment', $printer->fields['comment']); + $this->assertSame($states_id, $printer->fields['states_id']); + $this->assertSame($locations_id, $printer->fields['locations_id']); //inventory a new printer $xml_source = ' @@ -7447,18 +7521,18 @@ public function testBusinessRuleOnAddPrinter() //check created printer $printer = new \Printer(); - $this->boolean($printer->getFromDBByCrit(['serial' => 'E1234567890']))->isTrue(); - $this->string($printer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($printer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($printer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertTrue($printer->getFromDBByCrit(['serial' => 'E1234567890'])); + $this->assertSame('A comment', $printer->fields['comment']); + $this->assertSame($states_id, $printer->fields['states_id']); + $this->assertSame($locations_id, $printer->fields['locations_id']); //redo inventory $this->doInventory($xml_source, true); - $this->boolean($printer->getFromDBByCrit(['serial' => 'E1234567890']))->isTrue(); - $this->string($printer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($printer->fields['states_id'])->isIdenticalTo($states_id); + $this->assertTrue($printer->getFromDBByCrit(['serial' => 'E1234567890'])); + $this->assertSame('A comment', $printer->fields['comment']); + $this->assertSame($states_id, $printer->fields['states_id']); //location is not set by rule on update, but is set from inventory data - $this->integer($printer->fields['locations_id'])->isIdenticalTo(getItemByTypeName(\Location::class, 'Location', true)); + $this->assertSame(getItemByTypeName(\Location::class, 'Location', true), $printer->fields['locations_id']); } public function testBusinessRuleOnUpdatePrinter() @@ -7468,11 +7542,11 @@ public function testBusinessRuleOnUpdatePrinter() //prepare rule contents $state = new \State(); $states_id = $state->add(['name' => 'Test status']); - $this->integer($states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $states_id); $location = new \Location(); $locations_id = $location->add(['name' => 'Test location']); - $this->integer($locations_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $locations_id); //create rule $input_rule = [ @@ -7485,7 +7559,7 @@ public function testBusinessRuleOnUpdatePrinter() $rule = new \Rule(); $rules_id = $rule->add($input_rule); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria $input_criteria = [ @@ -7496,7 +7570,7 @@ public function testBusinessRuleOnUpdatePrinter() ]; $rule_criteria = new \RuleCriteria(); $rule_criteria_id = $rule_criteria->add($input_criteria); - $this->integer($rule_criteria_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_criteria_id); //create actions $input_action = [ @@ -7506,7 +7580,7 @@ public function testBusinessRuleOnUpdatePrinter() 'value' => $states_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -7515,7 +7589,7 @@ public function testBusinessRuleOnUpdatePrinter() 'value' => $locations_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -7524,30 +7598,30 @@ public function testBusinessRuleOnUpdatePrinter() 'value' => 'A comment' ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); //ensure business rule work on regular printer add $printer = new \Printer(); $printers_id = $printer->add(['name' => 'Test printer', 'entities_id' => 0]); - $this->integer($printers_id)->isGreaterThan(0); - $this->boolean($printer->getFromDB($printers_id))->isTrue(); + $this->assertGreaterThan(0, $printers_id); + $this->assertTrue($printer->getFromDB($printers_id)); - $this->variable($printer->fields['comment'])->isNull(); - $this->integer($printer->fields['states_id'])->isIdenticalTo(0); - $this->integer($printer->fields['locations_id'])->isIdenticalTo(0); + $this->assertNull($printer->fields['comment']); + $this->assertSame(0, $printer->fields['states_id']); + $this->assertSame(0, $printer->fields['locations_id']); //update printer - $this->boolean( + $this->assertTrue( $printer->update([ 'id' => $printers_id, 'comment' => 'Another comment' ]) - )->isTrue(); - $this->boolean($printer->getFromDB($printers_id))->isTrue(); + ); + $this->assertTrue($printer->getFromDB($printers_id)); - $this->string($printer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($printer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($printer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertSame('A comment', $printer->fields['comment']); + $this->assertSame($states_id, $printer->fields['states_id']); + $this->assertSame($locations_id, $printer->fields['locations_id']); //inventory a new printer $xml_source = ' @@ -7589,17 +7663,17 @@ public function testBusinessRuleOnUpdatePrinter() //check created printer $printer = new \Printer(); - $this->boolean($printer->getFromDBByCrit(['serial' => 'E1234567890']))->isTrue(); - $this->variable($printer->fields['comment'])->isNull(); - $this->integer($printer->fields['states_id'])->isIdenticalTo(0); - $this->integer($printer->fields['locations_id'])->isIdenticalTo(getItemByTypeName(\Location::class, 'Location', true)); + $this->assertTrue($printer->getFromDBByCrit(['serial' => 'E1234567890'])); + $this->assertNull($printer->fields['comment']); + $this->assertSame(0, $printer->fields['states_id']); + $this->assertSame(getItemByTypeName(\Location::class, 'Location', true), $printer->fields['locations_id']); //redo inventory $this->doInventory($xml_source, true); - $this->boolean($printer->getFromDBByCrit(['serial' => 'E1234567890']))->isTrue(); - $this->string($printer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($printer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($printer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertTrue($printer->getFromDBByCrit(['serial' => 'E1234567890'])); + $this->assertSame('A comment', $printer->fields['comment']); + $this->assertSame($states_id, $printer->fields['states_id']); + $this->assertSame($locations_id, $printer->fields['locations_id']); } public function testBusinessRuleOnAddAndOnUpdatePrinter() @@ -7609,11 +7683,11 @@ public function testBusinessRuleOnAddAndOnUpdatePrinter() //prepare rule contents $state = new \State(); $states_id = $state->add(['name' => 'Test status']); - $this->integer($states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $states_id); $location = new \Location(); $locations_id = $location->add(['name' => 'Test location']); - $this->integer($locations_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $locations_id); //create rule $input_rule = [ @@ -7626,7 +7700,7 @@ public function testBusinessRuleOnAddAndOnUpdatePrinter() $rule = new \Rule(); $rules_id = $rule->add($input_rule); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria $input_criteria = [ @@ -7637,7 +7711,7 @@ public function testBusinessRuleOnAddAndOnUpdatePrinter() ]; $rule_criteria = new \RuleCriteria(); $rule_criteria_id = $rule_criteria->add($input_criteria); - $this->integer($rule_criteria_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_criteria_id); //create actions $input_action = [ @@ -7647,7 +7721,7 @@ public function testBusinessRuleOnAddAndOnUpdatePrinter() 'value' => $states_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -7656,7 +7730,7 @@ public function testBusinessRuleOnAddAndOnUpdatePrinter() 'value' => $locations_id ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); $input_action = [ 'rules_id' => $rules_id, @@ -7665,30 +7739,30 @@ public function testBusinessRuleOnAddAndOnUpdatePrinter() 'value' => 'A comment' ]; $rule_action = new \RuleAction(); - $this->integer($rule_action->add($input_action))->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action->add($input_action)); //ensure business rule work on regular printer add $printer = new \Printer(); $printers_id = $printer->add(['name' => 'Test printer', 'entities_id' => 0]); - $this->integer($printers_id)->isGreaterThan(0); - $this->boolean($printer->getFromDB($printers_id))->isTrue(); + $this->assertGreaterThan(0, $printers_id); + $this->assertTrue($printer->getFromDB($printers_id)); - $this->string($printer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($printer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($printer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertSame('A comment', $printer->fields['comment']); + $this->assertSame($states_id, $printer->fields['states_id']); + $this->assertSame($locations_id, $printer->fields['locations_id']); //update network equipment - $this->boolean( + $this->assertTrue( $printer->update([ 'id' => $printers_id, 'comment' => 'Another comment' ]) - )->isTrue(); - $this->boolean($printer->getFromDB($printers_id))->isTrue(); + ); + $this->assertTrue($printer->getFromDB($printers_id)); - $this->string($printer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($printer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($printer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertSame('A comment', $printer->fields['comment']); + $this->assertSame($states_id, $printer->fields['states_id']); + $this->assertSame($locations_id, $printer->fields['locations_id']); //inventory a new printer $xml_source = ' @@ -7730,17 +7804,17 @@ public function testBusinessRuleOnAddAndOnUpdatePrinter() //check created printer $printer = new \Printer(); - $this->boolean($printer->getFromDBByCrit(['serial' => 'E1234567890']))->isTrue(); - $this->string($printer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($printer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($printer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertTrue($printer->getFromDBByCrit(['serial' => 'E1234567890'])); + $this->assertSame('A comment', $printer->fields['comment']); + $this->assertSame($states_id, $printer->fields['states_id']); + $this->assertSame($locations_id, $printer->fields['locations_id']); //redo inventory $this->doInventory($xml_source, true); - $this->boolean($printer->getFromDBByCrit(['serial' => 'E1234567890']))->isTrue(); - $this->string($printer->fields['comment'])->isIdenticalTo('A comment'); - $this->integer($printer->fields['states_id'])->isIdenticalTo($states_id); - $this->integer($printer->fields['locations_id'])->isIdenticalTo($locations_id); + $this->assertTrue($printer->getFromDBByCrit(['serial' => 'E1234567890'])); + $this->assertSame('A comment', $printer->fields['comment']); + $this->assertSame($states_id, $printer->fields['states_id']); + $this->assertSame($locations_id, $printer->fields['locations_id']); } public function testStatusIfInventoryOnAdd() @@ -7758,7 +7832,7 @@ public function testStatusIfInventoryOnAdd() $rule = new \Rule(); $rules_id = $rule->add($input_rule); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria $input_criteria = [ @@ -7769,11 +7843,11 @@ public function testStatusIfInventoryOnAdd() ]; $rule_criteria = new \RuleCriteria(); $rule_criteria_id = $rule_criteria->add($input_criteria); - $this->integer($rule_criteria_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_criteria_id); $state = new \State(); $states_id = $state->add(['name' => 'test_status_if_inventory']); - $this->integer($states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $states_id); //create action $input_action = [ @@ -7784,7 +7858,7 @@ public function testStatusIfInventoryOnAdd() ]; $rule_action = new \RuleAction(); $rule_action_id = $rule_action->add($input_action); - $this->integer($rule_action_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action_id); $xml_source = " @@ -7806,18 +7880,18 @@ public function testStatusIfInventoryOnAdd() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable(), "WHERE" => ['deviceid' => 'test_setstatusifinventory']]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check created computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertSame($states_id, $computer->fields['states_id']); //redo inventory $this->doInventory($xml_source, true); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertSame($states_id, $computer->fields['states_id']); } public function testStatusIfInventoryOnUpdate() @@ -7835,7 +7909,7 @@ public function testStatusIfInventoryOnUpdate() $rule = new \Rule(); $rules_id = $rule->add($input_rule); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria $input_criteria = [ @@ -7846,11 +7920,11 @@ public function testStatusIfInventoryOnUpdate() ]; $rule_criteria = new \RuleCriteria(); $rule_criteria_id = $rule_criteria->add($input_criteria); - $this->integer($rule_criteria_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_criteria_id); $state = new \State(); $states_id = $state->add(['name' => 'test_status_if_inventory']); - $this->integer($states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $states_id); //create action $input_action = [ @@ -7861,7 +7935,7 @@ public function testStatusIfInventoryOnUpdate() ]; $rule_action = new \RuleAction(); $rule_action_id = $rule_action->add($input_action); - $this->integer($rule_action_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action_id); $xml_source = " @@ -7883,18 +7957,18 @@ public function testStatusIfInventoryOnUpdate() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable(), "WHERE" => ['deviceid' => 'test_setstatusifinventory']]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check created computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->integer($computer->fields['states_id'])->isIdenticalTo(0); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertSame(0, $computer->fields['states_id']); //redo inventory $this->doInventory($xml_source, true); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertSame($states_id, $computer->fields['states_id']); } public function testStatusIfInventoryOnAddUpdate() @@ -7912,7 +7986,7 @@ public function testStatusIfInventoryOnAddUpdate() $rule = new \Rule(); $rules_id = $rule->add($input_rule); - $this->integer($rules_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rules_id); //create criteria $input_criteria = [ @@ -7923,11 +7997,11 @@ public function testStatusIfInventoryOnAddUpdate() ]; $rule_criteria = new \RuleCriteria(); $rule_criteria_id = $rule_criteria->add($input_criteria); - $this->integer($rule_criteria_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_criteria_id); $state = new \State(); $states_id = $state->add(['name' => 'test_status_if_inventory']); - $this->integer($states_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $states_id); //create action $input_action = [ @@ -7938,7 +8012,7 @@ public function testStatusIfInventoryOnAddUpdate() ]; $rule_action = new \RuleAction(); $rule_action_id = $rule_action->add($input_action); - $this->integer($rule_action_id)->isGreaterThan(0); + $this->assertGreaterThan(0, $rule_action_id); $xml_source = " @@ -7960,18 +8034,18 @@ public function testStatusIfInventoryOnAddUpdate() //check created agent $agents = $DB->request(['FROM' => \Agent::getTable(), "WHERE" => ['deviceid' => 'test_setstatusifinventory']]); - $this->integer(count($agents))->isIdenticalTo(1); + $this->assertCount(1, $agents); $agent = $agents->current(); //check created computer $computer = new \Computer(); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertSame($states_id, $computer->fields['states_id']); //redo inventory $this->doInventory($xml_source, true); - $this->boolean($computer->getFromDB($agent['items_id']))->isTrue(); - $this->integer($computer->fields['states_id'])->isIdenticalTo($states_id); + $this->assertTrue($computer->getFromDB($agent['items_id'])); + $this->assertSame($states_id, $computer->fields['states_id']); } public function testLocationHIerarchy() @@ -8025,19 +8099,19 @@ public function testLocationHIerarchy() //check created networkequipment $neteq = new \NetworkEquipment(); - $this->boolean($neteq->getFromDBByCrit(['serial' => 'SSI1912014B']))->isTrue(); + $this->assertTrue($neteq->getFromDBByCrit(['serial' => 'SSI1912014B'])); $locations = $DB->request(['FROM' => 'glpi_locations', 'ORDER' => 'id DESC']); - $this->integer(count($locations))->isIdenticalTo($count_locations + 2); + $this->assertCount($count_locations + 2, $locations); $new_location = $locations->current(); - $this->string($new_location['name'])->isIdenticalTo('Paris'); - $this->integer($new_location['locations_id'])->isGreaterThan(0); + $this->assertSame('Paris', $new_location['name']); + $this->assertGreaterThan(0, $new_location['locations_id']); $locations->next(); $parent_location = $locations->current(); - $this->string($parent_location['name'])->isIdenticalTo('France'); - $this->integer($parent_location['id'])->isIdenticalTo($new_location['locations_id']); + $this->assertSame('France', $parent_location['name']); + $this->assertSame($new_location['locations_id'], $parent_location['id']); } public function testPartialUser() @@ -8083,8 +8157,8 @@ public function testPartialUser() $this->doInventory($json); $computer = new \Computer(); - $this->boolean($computer->getFromDBByCrit(['name' => 'pc_with_user']))->isTrue(); - $this->string($computer->fields['contact'])->isIdenticalTo('guillaume'); + $this->assertTrue($computer->getFromDBByCrit(['name' => 'pc_with_user'])); + $this->assertSame('guillaume', $computer->fields['contact']); //change user, and redo inventory $json = json_decode($json_str); @@ -8093,8 +8167,8 @@ public function testPartialUser() $json->content->users[0]->login = $newuser; $this->doInventory($json); - $this->boolean($computer->getFromDBByCrit(['name' => 'pc_with_user']))->isTrue(); - $this->string($computer->fields['contact'])->isIdenticalTo($newuser); + $this->assertTrue($computer->getFromDBByCrit(['name' => 'pc_with_user'])); + $this->assertSame($newuser, $computer->fields['contact']); //make partial, change user, and redo inventory $json = json_decode($json_str); @@ -8104,7 +8178,7 @@ public function testPartialUser() $json->partial = true; $this->doInventory($json); - $this->boolean($computer->getFromDBByCrit(['name' => 'pc_with_user']))->isTrue(); - $this->string($computer->fields['contact'])->isIdenticalTo($newuser); + $this->assertTrue($computer->getFromDBByCrit(['name' => 'pc_with_user'])); + $this->assertSame($newuser, $computer->fields['contact']); } } diff --git a/tests/functional/Glpi/Inventory/Request.php b/phpunit/functional/Glpi/Inventory/Request.php similarity index 71% rename from tests/functional/Glpi/Inventory/Request.php rename to phpunit/functional/Glpi/Inventory/Request.php index afdbf187267..b44e2ef09b9 100644 --- a/tests/functional/Glpi/Inventory/Request.php +++ b/phpunit/functional/Glpi/Inventory/Request.php @@ -44,41 +44,33 @@ public function testConstructor() { //no mode without content $request = new \Glpi\Inventory\Request(); - $this->variable($request->getMode())->isNull(); - $this->variable($request->getResponse())->isIdenticalTo(""); + $this->assertNull($request->getMode()); + $this->assertSame("", $request->getResponse()); //no mode with content $request->addToResponse(["something" => "some content"]); - $this->exception( - function () use ($request) { - $this->variable($request->getResponse())->isNull(); - } - ) - ->isInstanceOf('\RuntimeException') - ->hasMessage('Mode has not been set'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Mode has not been set'); + $this->assertNull($request->getResponse()); - $this->exception( - function () use ($request) { - $this->variable($request->getContentType())->isNull(); - } - ) - ->isInstanceOf('\RuntimeException') - ->hasMessage('Mode has not been set'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Mode has not been set'); + $this->assertNull($request->getContentType()); - //XML mode + //XML mode $request = new \Glpi\Inventory\Request(); $request->handleContentType('application/xml'); - $this->integer($request->getMode())->isIdenticalTo(\Glpi\Inventory\Request::XML_MODE); - $this->string($request->getResponse())->isIdenticalTo("\n"); - $this->string($request->getContentType())->isIdenticalTo('application/xml'); + $this->assertSame(\Glpi\Inventory\Request::XML_MODE, $request->getMode()); + $this->assertSame("\n", $request->getResponse()); + $this->assertSame('application/xml', $request->getContentType()); //JSON mode $request = new \Glpi\Inventory\Request(); $request->handleContentType('application/json'); - $this->integer($request->getMode())->isIdenticalTo(\Glpi\Inventory\Request::JSON_MODE); + $this->assertSame(\Glpi\Inventory\Request::JSON_MODE, $request->getMode()); $response = []; - $this->string($request->getResponse())->isIdenticalTo(json_encode($response)); - $this->string($request->getContentType())->isIdenticalTo('application/json'); + $this->assertSame(json_encode($response), $request->getResponse()); + $this->assertSame('application/json', $request->getContentType()); } public function testProlog() @@ -87,10 +79,10 @@ public function testProlog() $request = new \Glpi\Inventory\Request(); $request->handleContentType('application/xml'); $request->handleRequest($data); - $this->string($request->getResponse())->isIdenticalTo("\n24SEND"); + $this->assertSame("\n24SEND", $request->getResponse()); } - protected function queriesProvider() + public static function queriesProvider() { return [ ['query' => 'INVENTORY'], //Request::INVENT_QUERY | Request::INVENT_ACTION @@ -112,15 +104,19 @@ protected function queriesProvider() public function testSnmpQuery($query) { $data = "\natoumized-device$query"; - $request = new \mock\Glpi\Inventory\Request(); - $this->calling($request)->inventory = null; - $this->calling($request)->prolog = null; + + $request = $this->getMockBuilder(\Glpi\Inventory\Request::class) + ->onlyMethods(['inventory', 'prolog']) + ->getMock(); + $request->method('inventory')->willReturn(null); + $request->method('prolog')->willReturn(null); + $request->handleContentType('Application/xml'); $request->handleRequest($data); - $this->string($request->getResponse())->isIdenticalTo("\n"); + $this->assertSame("\n", $request->getResponse()); } - protected function unhandledQueriesProvider() + public static function unhandledQueriesProvider() { return [ ['query' => 'register'], //Request::REGISTER_ACTION @@ -144,8 +140,8 @@ public function testWrongQuery($query) $request = new \Glpi\Inventory\Request(); $request->handleContentType('application/xml'); $request->handleRequest($data); - $this->integer($request->getHttpResponseCode())->isIdenticalTo(501); - $this->string($request->getResponse())->isIdenticalTo("\n"); + $this->assertSame(501, $request->getHttpResponseCode()); + $this->assertSame("\n", $request->getResponse()); } public function testAddError() @@ -153,14 +149,14 @@ public function testAddError() $request = new \Glpi\Inventory\Request(); $request->handleContentType('application/xml'); $request->addError('Something went wrong.'); - $this->string($request->getResponse())->isIdenticalTo("\n"); + $this->assertSame("\n", $request->getResponse()); } public function testAddResponse() { $request = new \Glpi\Inventory\Request(); $request->handleContentType('application/xml'); - //to test nodes with attributes + //to test nodes with attributes $request->addToResponse([ 'OPTION' => [ 'NAME' => 'NETDISCOVERY', @@ -213,10 +209,13 @@ public function testAddResponse() ] ]); - $this->string($request->getResponse())->isIdenticalTo("\n"); + $this->assertSame( + "\n", + $request->getResponse() + ); } - protected function compressionProvider(): array + public static function compressionProvider(): array { return [ [ @@ -259,7 +258,7 @@ public function testCompression(string $function, string $mime) $request = new \Glpi\Inventory\Request(); $request->handleContentType($mime); $request->handleRequest($cdata); - $this->string($request->getDeviceID())->isIdenticalTo('atoumized-device'); - $this->string($request->getResponse())->isIdenticalTo($function("\n24SEND")); + $this->assertSame('atoumized-device', $request->getDeviceID()); + $this->assertSame($function("\n24SEND"), $request->getResponse()); } } diff --git a/tests/functional/QueryParam.php b/phpunit/functional/QueryParamTest.php similarity index 87% rename from tests/functional/QueryParam.php rename to phpunit/functional/QueryParamTest.php index 0a3c2b8dced..7c7e8c2b784 100644 --- a/tests/functional/QueryParam.php +++ b/phpunit/functional/QueryParamTest.php @@ -39,9 +39,9 @@ /* Test for inc/dbutils.class.php */ -class QueryParam extends DbTestCase +class QueryParamTest extends DbTestCase { - protected function dataParams() + public static function dataParamsProvider() { return [ @@ -54,17 +54,17 @@ protected function dataParams() } /** - * @dataProvider dataParams + * @dataProvider dataParamsProvider */ public function testQueryParam($value, $expected) { $qpa = new \QueryParam($value); - $this->string($qpa->getValue())->isIdenticalTo($expected); + $this->assertSame($expected, $qpa->getValue()); } public function testEmptyQueryParam() { $qpa = new \QueryParam(); - $this->string($qpa->getValue())->isIdenticalTo('?'); + $this->assertSame('?', $qpa->getValue()); } } diff --git a/src/Session.php b/src/Session.php index 616785b3895..e6e2d99ce18 100644 --- a/src/Session.php +++ b/src/Session.php @@ -101,7 +101,9 @@ public static function init(Auth $auth) } } self::destroy(); - session_regenerate_id(); + if (!defined('TU_USER')) { //FIXME: no idea why this fails with phpunit... :( + session_regenerate_id(); + } self::start(); $_SESSION = $save; $_SESSION['valid_id'] = session_id(); diff --git a/src/SingletonRuleList.php b/src/SingletonRuleList.php index 672d265f8e0..48858bdaf0b 100644 --- a/src/SingletonRuleList.php +++ b/src/SingletonRuleList.php @@ -51,6 +51,12 @@ class SingletonRuleList **/ public static function &getInstance($type, $entity) { + //FIXME: can be removed when using phpunit 10 and process-isolation + if (defined('TU_USER')) { + $o = new self(); + return $o; + } + static $instances = []; if (!isset($instances[$type][$entity])) { diff --git a/tools/build_glpi.sh b/tools/build_glpi.sh index 8bbed955eee..c743a9faf60 100755 --- a/tools/build_glpi.sh +++ b/tools/build_glpi.sh @@ -83,6 +83,7 @@ dev_nodes=( "package.json" "package-lock.json" "phpstan.neon" + "phpunit.xml.dist" "PULL_REQUEST_TEMPLATE.md" "stubs" "tests"