expectException( NotesUnavailableException::class ); $callback(); remove_filter( 'woocommerce_data_stores', '__return_empty_array' ); } /** * @doesNotPerformAssertions * @dataProvider methods_never_causing_exception_provider * * @param callable $callback Tested NoteTraits method. */ public function test_no_exception_is_thrown_even_if_data_store_cannot_be_loaded( $callback ) { add_filter( 'woocommerce_data_stores', '__return_empty_array' ); $callback(); remove_filter( 'woocommerce_data_stores', '__return_empty_array' ); } /** * Test should convert to array if it's a stdClass object. * @return void */ public function test_possibly_convert_object_to_array() { $this->assertEquals( self::possibly_convert_object_to_array( new stdClass() ), array() ); $this->assertEquals( self::possibly_convert_object_to_array( 1 ), 1 ); $this->assertEquals( self::possibly_convert_object_to_array( 'string' ), 'string' ); } /** * Method required to use NoteTraits. * * @return Note */ public static function get_note() { return new Note(); } /** * Data provider providing methods that should throw an exception * only if the "admin-note" data store cannot be loaded. * * @return array[] */ public function methods_causing_exception_if_data_store_cannot_be_loaded_provider() { return array( array( function () { self::note_exists(); }, ), array( function () { self::can_be_added(); }, ), array( function () { self::possibly_add_note(); }, ), array( function () { self::add_note(); }, ), array( function () { self::possibly_delete_note(); }, ), array( function () { self::possibly_update_note(); }, ), array( function () { self::has_note_been_actioned(); }, ), ); } /** * Data provider providing methods that should not throw * an exception regardless of the data store being available. * * @return array[] */ public function methods_never_causing_exception_provider() { return array( array( function () { self::wc_admin_active_for( 123 ); }, ), ); } }