assertNotEmpty( $mutation_type_fields ); /** * If the fields are a populated array */ if ( ! empty( $mutation_type_fields ) && is_array( $mutation_type_fields ) ) { /** * Loop through the fields to ensure they have fields of their own */ foreach ( $mutation_type_fields as $mutation_type_field ) { $type = ! empty( $mutation_type_field['type'] ) ? $mutation_type_field['type'] : null; /** * All mutations should declare a Type */ $this->assertNotEmpty( $type ); /** * All types should have a "kind" */ $this->assertArrayHasKey( 'kind', $type ); /** * All rootMutations should be Object types */ $this->assertEquals( $type['kind'], 'OBJECT' ); /** * All rootMutations should have fields */ $this->assertNotEmpty( $type['fields'] ); /** * All rootMutations should have a clientMutationId field */ $this->assertTrue( $this->checkIfClientMutationIdExists( $type['fields'] ) ); } } } /** * This is a helper that searches an array to see if any nested items contain the "name" attribute * with a value of "clientMutationId" * * @param $array * * @return bool */ public function checkIfClientMutationIdExists( $array ) { $this->assertNotEmpty( $array ); foreach ( $array as $item ) { if ( 'clientMutationId' === $item['name'] ) { return true; } } return false; } }