Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant asserts #1312

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions core/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ protected function __construct()
{
assert(!empty($this->key), "key field is required");
assert(!empty($this->name), "name field is required for extension $this->key");
assert(is_array($this->db_support), "db_support has to be an array for extension $this->key");
assert(is_array($this->authors), "authors has to be an array for extension $this->key");
assert(is_array($this->dependencies), "dependencies has to be an array for extension $this->key");
}

public function is_enabled(): bool
Expand Down
8 changes: 4 additions & 4 deletions core/tests/InitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class InitTest extends TestCase
{
public function testInitExt(): void
{
send_event(new InitExtEvent());
$this->assertTrue(true);
$e = send_event(new InitExtEvent());
$this->assertFalse($e->stop_processing);
}

public function testDatabaseUpgrade(): void
{
send_event(new DatabaseUpgradeEvent());
$this->assertTrue(true);
$e = send_event(new DatabaseUpgradeEvent());
$this->assertFalse($e->stop_processing);
}
}
12 changes: 6 additions & 6 deletions core/tests/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function test_page(): void
$page->set_mode(PageMode::PAGE);
ob_start();
$page->display();
$this->assertGreaterThan(0, ob_get_length());
ob_end_clean();
$this->assertTrue(true); // doesn't crash
}

public function test_file(): void
Expand All @@ -27,8 +27,8 @@ public function test_file(): void
$page->set_file("tests/pbx_screenshot.jpg");
ob_start();
$page->display();
$this->assertGreaterThan(0, ob_get_length());
ob_end_clean();
$this->assertTrue(true); // doesn't crash
}

public function test_data(): void
Expand All @@ -38,8 +38,8 @@ public function test_data(): void
$page->set_data("hello world");
ob_start();
$page->display();
$this->assertGreaterThan(0, ob_get_length());
ob_end_clean();
$this->assertTrue(true); // doesn't crash
}

public function test_redirect(): void
Expand All @@ -49,15 +49,15 @@ public function test_redirect(): void
$page->set_redirect("/new/page");
ob_start();
$page->display();
$this->assertGreaterThan(0, ob_get_length());
ob_end_clean();
$this->assertTrue(true); // doesn't crash
}

public function test_subNav(): void
{
// the default theme doesn't send this, so let's have
// a random test manually
send_event(new PageSubNavBuildingEvent("system"));
$this->assertTrue(true); // doesn't crash
$e = send_event(new PageSubNavBuildingEvent("system"));
$this->assertGreaterThan(0, count($e->links));
}
}
9 changes: 3 additions & 6 deletions core/tests/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@ public function test_get_theme(): void

public function test_get_memory_limit(): void
{
get_memory_limit();
$this->assertTrue(true);
$this->assertGreaterThan(0, get_memory_limit());
}

public function test_check_gd_version(): void
{
check_gd_version();
$this->assertTrue(true);
$this->assertGreaterThanOrEqual(0, check_gd_version());
}

public function test_check_im_version(): void
{
check_im_version();
$this->assertTrue(true);
$this->assertGreaterThanOrEqual(0, check_im_version());
}

public function test_human_filesize(): void
Expand Down
4 changes: 2 additions & 2 deletions ext/admin/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testAct(): void
public function testCliGen(): void
{
$app = new CliApp();
send_event(new CliGenEvent($app));
$this->assertTrue(true); // TODO: check for more than "no crash"?
$e = send_event(new CliGenEvent($app));
$this->assertFalse($e->stop_processing);
}
}
6 changes: 0 additions & 6 deletions ext/comment/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ public function display_comment_list(array $images, int $page_number, int $total
{
global $config, $page, $user;

// aaaaaaargh php
assert(is_array($images));
assert(is_numeric($page_number));
assert(is_numeric($total_pages));
assert(is_bool($can_post));

// parts for the whole page
$prev = $page_number - 1;
$next = $page_number + 1;
Expand Down
2 changes: 0 additions & 2 deletions ext/favorites/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class FavoriteSetEvent extends Event
public function __construct(int $image_id, User $user, bool $do_set)
{
parent::__construct();
assert(is_int($image_id));
assert(is_bool($do_set));

$this->image_id = $image_id;
$this->user = $user;
Expand Down
2 changes: 1 addition & 1 deletion ext/graphql/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function testSchema(): void
{
$schema = GraphQL::get_schema();
$schema->assertValid();
$this->assertTrue(true);
$this->assertNotEmpty($schema->getTypeMap());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions ext/help_pages/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class HelpPagesTest extends ShimmiePHPUnitTestCase
{
public function test_list(): void
{
send_event(new HelpPageListBuildingEvent());
$this->assertTrue(true);
$e = send_event(new HelpPageListBuildingEvent());
$this->assertGreaterThan(0, count($e->pages));
}

public function test_page(): void
{
send_event(new HelpPageBuildingEvent("test"));
$this->assertTrue(true);
$e = send_event(new HelpPageBuildingEvent("test"));
$this->assertEquals(0, count($e->get_parts()));
}
}
3 changes: 1 addition & 2 deletions ext/image/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@ public function onDatabaseUpgrade(DatabaseUpgradeEvent $event): void

public function onPageRequest(PageRequestEvent $event): void
{
global $config, $page;
global $config, $page, $user;

$thumb_width = $config->get_int(ImageConfig::THUMB_WIDTH, 192);
$thumb_height = $config->get_int(ImageConfig::THUMB_HEIGHT, 192);
$page->add_html_header(STYLE(":root {--thumb-width: {$thumb_width}px; --thumb-height: {$thumb_height}px;}"));

if ($event->page_matches("image/delete", method: "POST", permission: Permissions::DELETE_IMAGE)) {
global $page, $user;
$image = Image::by_id(int_escape($event->req_POST('image_id')));
if ($image) {
send_event(new ImageDeletionEvent($image));
Expand Down
3 changes: 2 additions & 1 deletion ext/image/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ public function testUserStats(): void

public function testDeleteRequest(): void
{
global $page;
$this->log_in_as_admin();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test");
send_event(new PageRequestEvent("POST", "image/delete", [], ['image_id' => "$image_id"]));
$this->assertTrue(true); // FIXME: assert image was deleted?
$this->assertEquals(PageMode::REDIRECT, $page->mode);
}
}
4 changes: 2 additions & 2 deletions ext/index/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public function testIndexPage(): void
public function test_nav(): void
{
send_event(new UserLoginEvent(User::by_name(self::$user_name)));
send_event(new PageNavBuildingEvent());
$e = send_event(new PageNavBuildingEvent());
$this->assertGreaterThan(0, count($e->links));
// just a few common parents
foreach (["help", "posts", "system", "user"] as $parent) {
send_event(new PageSubNavBuildingEvent($parent));
}
$this->assertTrue(true);
}

public function test_operands(): void
Expand Down
1 change: 1 addition & 0 deletions ext/media/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ public static function image_resize_gd(
throw new MediaException("Could not load image: " . $image_filename);
}

assert($new_width > 0 && $new_height > 0);
$image_resized = imagecreatetruecolor($new_width, $new_height);
if ($image_resized === false) {
throw new MediaException("Could not create output image with dimensions $new_width x $new_height ");
Expand Down
6 changes: 2 additions & 4 deletions ext/pools/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public function testCreate(): array
$this->log_in_as_user();
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
$image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "pbx");
$this->assertNotNull($image_id_1);
$this->assertNotNull($image_id_2);

$this->get_page("pool/new");

Expand All @@ -53,6 +51,8 @@ public function testCreate(): array
$pool_id = (int)(explode("/", $page->redirect)[4]);
send_event(new PoolAddPostsEvent($pool_id, [$image_id_1, $image_id_2]));

$this->assertGreaterThan(0, $pool_id);

return [$pool_id, [$image_id_1, $image_id_2]];
}

Expand Down Expand Up @@ -167,8 +167,6 @@ public function testNuke(): void
$this->log_in_as_user();
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
$image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "pbx");
$this->assertNotNull($image_id_1);
$this->assertNotNull($image_id_2);

$this->get_page("pool/new");

Expand Down
4 changes: 2 additions & 2 deletions ext/res_limit/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public function testResLimitOK(): void
$config->set_string("upload_ratios", "4:3 16:9");

$this->log_in_as_user();
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
//$this->assert_response(302);
$this->assertTrue(true); // no exceptions
$this->assertNotNull(Image::by_id($image_id));
}

public function testResLimitSmall(): void
Expand Down
2 changes: 1 addition & 1 deletion ext/user/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ public function testCreateOther(): void
'email' => '',
]);
$this->assertEquals(302, $page->code);
$this->assertNotNull(User::by_name('testnew'));
User::by_name('testnew');
}
}
4 changes: 1 addition & 3 deletions ext/user_config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ public function onPageRequest(PageRequestEvent $event): void

if (!empty($user_id)) {
$user = User::by_id($user_id);
if ($user !== null) {
send_event(new UserLoginEvent($user));
}
send_event(new UserLoginEvent($user));
}
}

Expand Down