Skip to content

Commit

Permalink
FIrst pass at the new Inventory schema
Browse files Browse the repository at this point in the history
  • Loading branch information
sfreytag committed Oct 9, 2024
1 parent 5d07eeb commit 986d3db
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
53 changes: 53 additions & 0 deletions src/Schema/InventorySchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace CloudForest\ApiClientPhp\Schema;

/**
* InventorySchema defines the shape of the inventory data used to send an
* inventory to the CloudForest Api.
*
* @package CloudForest\Schema
*/
class InventorySchema
{
/**
* The ID of the inventory. If known, it is a UUID string, else null.
*
* @var string|null
*/
public $id = null;

/**
* Any notes about the inventory, or null if none.
*
* @var string|null
*/
public $notes = null;

/**
* The year the inventory was taken as a 'YYYY' string. Cannot be null
*
* @var string
*/
public $year = '2024';

/**
* The total volume of this inventory (and hence its parent subcompartment)
* as a number representing m^3, or null if not known.
*
* @var float|null
*/
public $volumeTotal = null;

/**
* The total base area of this inventory (and hence its parent
* subcompartment) as a number representing m^2, or null if not known.
*
* @var float|null
*/
public $basalAreaTotal = null;

// @todo Stratums
}
10 changes: 9 additions & 1 deletion src/Schema/SubcompartmentSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace CloudForest\ApiClientPhp\Schema;

use CloudForest\ApiClientPhp\Schema\GeojsonSchema;
use CloudForest\ApiClientPhp\Schema\InventorySchema;

enum SubcompartmentType: string
{
Expand Down Expand Up @@ -82,7 +83,14 @@ class SubcompartmentSchema
*/
public $area = null;

/** @todo inventorys */
/**
* The inventories that have been taken for this Subcompartment. The field
* spelling 'inventorys' is to keep a consistent pattern of plurals
* thoughout this schema.
*
* @var Array<InventorySchema>
*/
public $inventorys = [];

/**
* Constructor. Instantiate classes where required.
Expand Down
20 changes: 19 additions & 1 deletion tests/api/ListingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use CloudForest\ApiClientPhp\Schema\GeojsonGeometrySchema;
use CloudForest\ApiClientPhp\Schema\GeojsonGeometryType;
use CloudForest\ApiClientPhp\Schema\GeojsonSchema;
use CloudForest\ApiClientPhp\Schema\InventorySchema;
use CloudForest\ApiClientPhp\Schema\SubcompartmentSchema;
use CloudForest\ApiClientPhp\Schema\SubcompartmentType;

Expand Down Expand Up @@ -64,7 +65,16 @@ public function testCreate(): void
$subcompartment->centroid = $centroid;
$subcompartment->area = 12.36;

// Inventory 5, attach the subcompartment to the compartment
// Inventory 5, create an inventory record for the subcompartment
$inventory = new InventorySchema();
$inventory->id = null;
$inventory->notes = 'These are the inventory notes';
$inventory->year = '1999';
$inventory->volumeTotal = 1234.5;
$inventory->basalAreaTotal = 2000.1;

// Inventory 6, create the structure
$subcompartment->inventorys = [$inventory];
$compartment->subcompartments = [$subcompartment];

// Create a listing and attach the inventory
Expand Down Expand Up @@ -97,5 +107,13 @@ public function testCreate(): void
$subcompartment = $compartment['subcompartments'][0];
$this->assertEquals('PHPUnit Forest Subcompartment', $subcompartment['name']);
$this->assertEquals('B', $subcompartment['letter']);

// Verify the returned listing's inventory has the same data as above.
$this->assertIsArray($subcompartment['inventorys']);
$this->assertCount(1, $subcompartment['inventorys']);
$inventory = $subcompartment['inventorys'][0];
$this->assertEquals('These are the inventory notes', $inventory['notes']);
$this->assertEquals('1999', $inventory['year']);
$this->assertEquals('2000.1', $inventory['basalAreaTotal']);
}
}

0 comments on commit 986d3db

Please sign in to comment.