pluginName = 'some-plugin/some-plugin.php'; $this->slug = 'some-plugin'; $this->version = '0.1'; $this->updater = new Updater( $this->pluginName, $this->slug, $this->version ); } public function testItInitializes() { $updater = Stub::make( $this->updater, [ 'checkForUpdate' => Expected::once(), ], $this ); $updater->init(); apply_filters('pre_set_site_transient_update_plugins', null); } public function testItChecksForUpdates() { $updateTransient = new \stdClass; $updateTransient->lastChecked = time(); $updater = Stub::construct( $this->updater, [ $this->pluginName, $this->slug, $this->version, ], [ 'getLatestVersion' => function () { return (object)[ 'id' => 76630, 'slug' => $this->slug, 'plugin' => $this->pluginName, 'new_version' => $this->version . 1, 'url' => 'http://www.mailpoet.com/wordpress-newsletter-plugin-premium/', 'package' => home_url() . '/wp-content/uploads/mailpoet-premium.zip', ]; }, ], $this ); $result = $updater->checkForUpdate($updateTransient); expect($result->lastChecked)->greaterOrEquals($updateTransient->lastChecked); expect($result->checked[$this->pluginName])->equals($this->version); expect($result->response[$this->pluginName]->slug)->equals($this->slug); expect($result->response[$this->pluginName]->plugin)->equals($this->pluginName); expect(version_compare( $this->version, $result->response[$this->pluginName]->new_version, '<' ))->true(); expect($result->response[$this->pluginName]->package)->notEmpty(); } public function testItReturnsObjectIfPassedNonObjectWhenCheckingForUpdates() { $result = $this->updater->checkForUpdate(null); expect($result instanceof \stdClass)->true(); } }