UnitTester::assertEmpty PHP Method

assertEmpty() public method

Checks that variable is empty.
See also: Codeception\Module\Asserts::assertEmpty()
public assertEmpty ( $actual, string $message = null )
$actual
$message string
    public function assertEmpty($actual, $message = null)
    {
        return $this->scenario->runStep(new \Codeception\Step\Action('assertEmpty', func_get_args()));
    }

Usage Example

 /**
  * @depends testInstall
  */
 public function testProperties()
 {
     $object_id = 3;
     //1. Add TAG taxonomy
     $term = new TaxonomyDef();
     $term->name = 'test_property';
     $term->class = PropertyTerm::className();
     $term->data_table = 'sample_property';
     $term->ref_table = SampleTable::className();
     $this->tester->assertTrue($term->save());
     //2. Create data table
     $this->tester->assertFalse($this->getTaxonomy()->getTerm($term->name)->isInstalled(), 'The term should NOT be installed.');
     $this->getTaxonomy()->getTerm($term->name)->install();
     $this->tester->assertTrue($this->getTaxonomy()->getTerm($term->name)->isInstalled(), 'The term should be installed.');
     //3. Add some data
     $this->getTaxonomy()->addTerm($term->name, $object_id, ['prop1' => 'value1', 'prop2' => 'value2']);
     $term->refresh();
     //check count on term
     $this->tester->assertEquals(2, $term->total_count, 'Tag term count not correct!');
     //check update of field
     $this->getTaxonomy()->addTerm($term->name, $object_id, ['prop1' => 'value1_update']);
     $data = $this->getTaxonomy()->getTerms($term->name, $object_id);
     $this->tester->assertEquals('value1_update', $data['prop1'], 'Property value not updated');
     // 4. Test PropertyTerm::setTerms()
     $term = $this->getTaxonomy()->getTerm($term->name);
     $term->setTerms($object_id, ['prop1' => 'value1', 'prop3' => 'value3']);
     $data = $term->getTerms($object_id);
     $this->tester->assertTrue(array_key_exists('prop1', $data), 'Property prop1 is missing');
     $this->tester->assertTrue(array_key_exists('prop3', $data), 'Property prop3 is missing');
     $this->tester->assertFalse(array_key_exists('prop2', $data), 'Property prop2 must not be here');
     // 5. Test PropertyTerm::removeTerm()
     $term->removeTerm($object_id, array_keys($data));
     $data = $term->getTerms($object_id);
     $this->tester->assertEmpty($data, 'Data must be empty');
 }
All Usage Examples Of UnitTester::assertEmpty