PHP Classes

File: tests/Integration/ErrorHandlingTest.php

Recommend this page to a friend!
  Packages of Gianfrancesco Aurecchia   OPC UA Client   tests/Integration/ErrorHandlingTest.php   Download  
File: tests/Integration/ErrorHandlingTest.php
Role: Example script
Content type: text/plain
Description: Example script
Class: OPC UA Client
Control devices that support the OPC UA protocol
Author: By
Last change:
Date: 6 days ago
Size: 1,897 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

use
PhpOpcua\Client\Tests\Integration\Helpers\TestHelper;
use
PhpOpcua\Client\Types\BuiltinType;
use
PhpOpcua\Client\Types\NodeId;
use
PhpOpcua\Client\Types\StatusCode;

describe('Error Handling', function () {

   
it('returns BadNodeIdUnknown for a non-existent node', function () {
       
$client = null;
        try {
           
$client = TestHelper::connectNoSecurity();

           
$dv = $client->read(NodeId::string(1, 'NonExistentNode'));
           
expect(StatusCode::isBad($dv->getStatusCode()))->toBeTrue();
           
expect($dv->getStatusCode())->toBe(StatusCode::BadNodeIdUnknown);
        } finally {
           
TestHelper::safeDisconnect($client);
        }
    })->
group('integration');

   
it('returns BadNotWritable when writing to a read-only node', function () {
       
$client = null;
        try {
           
$client = TestHelper::connectNoSecurity();

           
// Read-only scalar nodes
           
$nodeId = TestHelper::browseToNode($client, ['TestServer', 'DataTypes', 'ReadOnly', 'Boolean_RO']);

           
$status = $client->write($nodeId, true, BuiltinType::Boolean);
           
expect(StatusCode::isBad($status))->toBeTrue();
           
expect($status)->toBe(StatusCode::BadNotWritable);
        } finally {
           
TestHelper::safeDisconnect($client);
        }
    })->
group('integration');

   
it('returns Bad status when reading with invalid attribute', function () {
       
$client = null;
        try {
           
$client = TestHelper::connectNoSecurity();

           
// Read the Server node with an invalid attribute ID (e.g. 99)
           
$dv = $client->read(NodeId::numeric(0, 2253), 99);
           
expect(StatusCode::isBad($dv->getStatusCode()))->toBeTrue();
        } finally {
           
TestHelper::safeDisconnect($client);
        }
    })->
group('integration');

})->
group('integration');