require_relative "spec_helper"

describe "A PHP application intended for Composer 1" do
	context "with a composer.lock generated by a very old version of Composer 1 (without a platform-api-version entry)" do
		it "rejects the lock file" do
			new_app_with_stack_and_platrepo_and_bin_report_dumper('test/fixtures/composer/basic_lock_oldv1', allow_failure: true).deploy do |app|
				errmsg = "ERROR: No Composer plugin-api-version recorded in composer.lock; file must be very old. Please update it using a recent version of Composer."
				expect(app.output).to include(errmsg)
				expect(app.bin_report_dump).to include(
					"failure_reason" => "composer_lock.parse",
					"failure_detail" => a_string_including(errmsg),
					"open_timers" => "__main__,platform.prepare",
				)
			end
		end
	end
	context "with a composer.lock generated by a late version 1 of Composer (with a platform-api-version entry)" do
		it "fails to build due to missing Composer 1 support" do
			new_app_with_stack_and_platrepo_and_bin_report_dumper('test/fixtures/composer/basic_lock_v1', allow_failure: true).deploy do |app|
				errmsg = "requires composer-plugin-api ^1"
				expect(app.output).to include("Failed to install system packages!")
				expect(app.output).to include(errmsg)
				expect(app.bin_report_dump).to include(
					"failure_reason" => "platform.install.main.solving",
					"failure_detail" => a_string_including(errmsg),
					"open_timers" => "__main__,platform.install,platform.install.main",
				)
			end
		end
	end
end
